App.tsx 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React, { FC, useEffect, useRef, useState } from 'react';
  2. import FilePicker from './components/file-picker';
  3. import CodeBox from './components/code-box';
  4. const App: FC = () => {
  5. const [err, setErr] = useState<string | Error | null>(null);
  6. const [files, setFiles] = useState<File[] | null>([]);
  7. const cbRef = useRef<HTMLDivElement>(null);
  8. useEffect(() => {
  9. if (files && files.length) {
  10. cbRef.current!.scrollIntoView({
  11. behavior: 'smooth' // Hopefully IE just ignores this value
  12. });
  13. }
  14. }, [files]);
  15. return (
  16. <>
  17. <div style={{
  18. display: 'flex',
  19. fontSize: '70px',
  20. justifyContent: 'space-between',
  21. flexDirection: 'row',
  22. overflow: 'hidden',
  23. width: '100%',
  24. fontWeight: 'bold'
  25. }}>
  26. <div style={{ paddingLeft: '0.25em' }}>
  27. fflate
  28. <div style={{
  29. color: 'gray',
  30. fontSize: '0.25em',
  31. fontWeight: 'lighter'
  32. }}>a fast compression library by <a href="//github.com/101arrowz" style={{ color: 'gray' }}>101arrowz</a></div>
  33. </div>
  34. <a href="//github.com/101arrowz/fflate">
  35. <svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" viewBox="0 0 250 250" fill="white">
  36. <path d="M0 0l115 115h15l12 27 108 108V0z" fill="black"/>
  37. <path d="M128 109c-15-9-9-19-9-19 3-7 2-11 2-11-1-7 3-2 3-2 4 5 2 11 2 11-3 10 5 15 9 16" style={{ transformOrigin: '130px 106px' }} />
  38. <path d="M115 115s4 2 5 0l14-14c3-2 6-3 8-3-8-11-15-24 2-41 5-5 10-7 16-7 1-2 3-7 12-11 0 0 5 3 7 16 4 2 8 5 12 9s7 8 9 12c14 3 17 7 17 7-4 8-9 11-11 11 0 6-2 11-7 16-16 16-30 10-41 2 0 3-1 7-5 11l-12 11c-1 1 1 5 1 5z"/>
  39. </svg>
  40. </a>
  41. </div>
  42. <div style={{
  43. display: 'flex',
  44. justifyContent: 'center',
  45. alignItems: 'center',
  46. flexDirection: 'column',
  47. textAlign: 'center',
  48. width: '100%',
  49. flex: 1
  50. }}>
  51. <div style={{ maxWidth: '80%', fontSize: 'calc(15px + 0.6vw)', paddingTop: '4vh', paddingBottom: '2vh' }}>
  52. You've found <a href="//npmjs.com/package/fflate">fflate</a>, the fastest pure JavaScript compression library in existence.
  53. <br /><br />
  54. You can both pack and expand Zlib, GZIP, DEFLATE, or ZIP files very quickly with just a few lines of code.
  55. <br /><br />
  56. Weighing in at a measly 8kB for basic compression and decompression, you don't need to worry about your bundle size ballooning.
  57. <br /><br />
  58. Despite utilizing multiple cores, supporting data streams, and being very memory efficient, fflate is compatible with both Node.js and browsers as old as IE11.
  59. <br /><br />
  60. You can read more about fflate on <a href="//github.com/101arrowz/fflate">GitHub</a>. Try the demo below to see its performance for yourself. The code boxes are editable; try changing parameters or using a different compression format.
  61. <br /><br />
  62. <span style={{ fontSize: '0.75em' }}>Disclaimer: I added a <span style={{ fontStyle: 'italic' }}>lot</span> of sugar (around 4 hundred lines) to the UZIP and Pako APIs to make the demo clean and asynchronous, but the fflate API is unmodified.</span>
  63. <br /><br />
  64. </div>
  65. <div style={{
  66. width: '100%',
  67. display: 'flex',
  68. alignItems: 'center',
  69. flexDirection: 'column',
  70. marginBottom: '2vh'
  71. }}>
  72. <FilePicker allowDirs onFiles={setFiles} onError={setErr} onDrag={() => {}}>
  73. {err && <div style={{ color: 'red' }}>Error: {err}</div>}
  74. <div>{files ? ((files.length || 'No') + ' file' + (files.length == 1 ? '' : 's') + ' selected') : 'Loading...'}</div>
  75. <br />
  76. </FilePicker>
  77. {((!files || files.length) && <CodeBox files={files!} forwardRef={cbRef} />) || null}
  78. </div>
  79. </div>
  80. </>
  81. );
  82. }
  83. export default App;