From b000728845535336cc1fc52d6d3d13c8add3ed20 Mon Sep 17 00:00:00 2001 From: ChAoS_UnItY Date: Sun, 5 Jun 2022 13:48:38 +0800 Subject: [PATCH] compress.gzip / deflate: rename gzip module into deflate module (#14682) --- vlib/compress/README.md | 2 +- vlib/compress/deflate/README.md | 21 +++++++++++++++++++ .../{gzip/gzip.v => deflate/deflate.v} | 2 +- .../gzip_test.v => deflate/deflate_test.v} | 6 +++++- vlib/compress/gzip/README.md | 17 --------------- 5 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 vlib/compress/deflate/README.md rename vlib/compress/{gzip/gzip.v => deflate/deflate.v} (96%) rename vlib/compress/{gzip/gzip_test.v => deflate/deflate_test.v} (58%) delete mode 100644 vlib/compress/gzip/README.md diff --git a/vlib/compress/README.md b/vlib/compress/README.md index 166e052b47..b7b2f513ab 100644 --- a/vlib/compress/README.md +++ b/vlib/compress/README.md @@ -1,4 +1,4 @@ ## Description: `compress` is a namespace for (multiple) compression algorithms supported by V. -At the moment, only `compress.zlib` and `compress.gzip` are implemented. +At the moment, only `compress.zlib` and `compress.deflate` are implemented. diff --git a/vlib/compress/deflate/README.md b/vlib/compress/deflate/README.md new file mode 100644 index 0000000000..40d70eda15 --- /dev/null +++ b/vlib/compress/deflate/README.md @@ -0,0 +1,21 @@ +## Description: + +`compress.deflate` is a module that assists in the compression and +decompression of binary data using `deflate` compression + +NOTE: To decompress gzip, discard first 10 bytes of compressed bytes +then use `compress.deflate.decompress`. (Header validation won't be +performed in this case) + +## Examples: + +```v +import compress.deflate + +fn main() { + uncompressed := 'Hello world!' + compressed := deflate.compress(uncompressed.bytes())? + decompressed := deflate.decompress(compressed)? + assert decompressed == uncompressed.bytes() +} +``` \ No newline at end of file diff --git a/vlib/compress/gzip/gzip.v b/vlib/compress/deflate/deflate.v similarity index 96% rename from vlib/compress/gzip/gzip.v rename to vlib/compress/deflate/deflate.v index 5213e319d8..5f66630ab4 100644 --- a/vlib/compress/gzip/gzip.v +++ b/vlib/compress/deflate/deflate.v @@ -1,4 +1,4 @@ -module gzip +module deflate import compress diff --git a/vlib/compress/gzip/gzip_test.v b/vlib/compress/deflate/deflate_test.v similarity index 58% rename from vlib/compress/gzip/gzip_test.v rename to vlib/compress/deflate/deflate_test.v index 2c91137be8..0dcd50df94 100644 --- a/vlib/compress/gzip/gzip_test.v +++ b/vlib/compress/deflate/deflate_test.v @@ -1,8 +1,12 @@ -module gzip +module deflate + +const gzip_magic_numbers = [u8(0x1f), 0x8b] fn test_gzip() ? { uncompressed := 'Hello world!' compressed := compress(uncompressed.bytes())? + first2 := compressed[0..2] + assert first2 != deflate.gzip_magic_numbers decompressed := decompress(compressed)? assert decompressed == uncompressed.bytes() } diff --git a/vlib/compress/gzip/README.md b/vlib/compress/gzip/README.md deleted file mode 100644 index 20f5aefa1f..0000000000 --- a/vlib/compress/gzip/README.md +++ /dev/null @@ -1,17 +0,0 @@ -## Description: - -`compress.gzip` is a module that assists in the compression and -decompression of binary data using `gzip` compression - -## Examples: - -```v -import compress.gzip - -fn main() { - uncompressed := 'Hello world!' - compressed := gzip.compress(uncompressed.bytes())? - decompressed := gzip.decompress(compressed)? - assert decompressed == uncompressed.bytes() -} -``` \ No newline at end of file