Fireship · @fireship

gzip file compression in 100 Seconds

Uploaded July 15, 2022 · Length 2:18

gzip file compression in 100 Seconds

Summary

gzip explained: a lossless file compression tool that reduces data size without losing information.

  • gzip
  • file compression
  • lossless compression
  • data compression
  • linux utilities

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    gzip a lossless file compression tool

  2. 0:02

    famous for making large chunks of data

  3. 0:04

    smaller the files on a computer are

  4. 0:06

    represented by bits on a silicon chip

  5. 0:08

    but they often take up more space than

  6. 0:10

    is actually necessary for example when

  7. 0:12

    you write your screenplay in a text

  8. 0:14

    document you produce a bunch of repeated

  9. 0:16

    patterns many years ago computer

  10. 0:18

    scientists realized we were wasting

  11. 0:19

    space and wrote algorithms like lz77 to

  12. 0:22

    address this problem by looping over the

  13. 0:24

    contents of a file to identify repeated

  14. 0:26

    sequences that can be replaced with

  15. 0:28

    metadata or shorter sequences thus

  16. 0:30

    reducing the total amount of bits

  17. 0:31

    required to represent the information

  18. 0:33

    most importantly no information is lost

  19. 0:36

    this differs from lossy compression

  20. 0:37

    algorithms like jpeg which can make an

  21. 0:39

    image file smaller but information is

  22. 0:41

    lost in the process gzip was developed

  23. 0:44

    by jean-luc guys and mark alder in 1992

  24. 0:47

    because the big evil tech corporations

  25. 0:48

    held the patents on existing compression

  26. 0:50

    technology their implementation is based

  27. 0:52

    on the deflate compression algorithm

  28. 0:54

    which is a combination of lz77 and

  29. 0:57

    huffman coding gzip is not the only game

  30. 0:59

    in town and other formats like zip 7zip

  31. 1:02

    and rar solve similar problems on the

  32. 1:04

    web gzip is the most common way to

  33. 1:06

    implement end-to-end compression where a

  34. 1:08

    file is compressed on the server then

  35. 1:10

    decompressed by the browser to reduce

  36. 1:12

    the amount of data sent over the network

  37. 1:14

    although broadly is a newer compression

  38. 1:15

    algorithm that's generally superior for

  39. 1:17

    files on the web to get started open up

  40. 1:19

    any linux machine where you'll find gzip

  41. 1:21

    installed by default as one of the most

  42. 1:23

    popular utilities of the gnu project to

  43. 1:25

    compress a file use the gzip command

  44. 1:27

    followed by the file name that creates a

  45. 1:29

    new file ending in gz that should be

  46. 1:31

    significantly smaller run the command

  47. 1:33

    again with the l flag to print out the

  48. 1:35

    compression ratio the higher the ratio

  49. 1:37

    the more space that was saved now use

  50. 1:39

    the d flag to decompress the file back

  51. 1:41

    to its original form or better yet use

  52. 1:44

    the gunzip command in the real world

  53. 1:46

    though you'll often want to compress

  54. 1:47

    multiple files at the same time gzip on

  55. 1:50

    its own cannot compress an entire

  56. 1:51

    directory for that you'll need to bring

  57. 1:53

    in an archiver like tar its name is

  58. 1:55

    derived from tape archive and what it

  59. 1:57

    does is take multiple files and combine