mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
compress.deflate,compress.gzip,compress.zlib,compress.zstd: fix v doc -unsafe-run-examples -f none vlib/compress/
too
This commit is contained in:
parent
33602047bc
commit
50e2d0344f
4 changed files with 8 additions and 8 deletions
|
@ -3,13 +3,13 @@ module deflate
|
||||||
import compress as compr
|
import compress as compr
|
||||||
|
|
||||||
// compresses an array of bytes using deflate and returns the compressed bytes in a new array
|
// compresses an array of bytes using deflate and returns the compressed bytes in a new array
|
||||||
// Example: compressed := deflate.compress(b)!
|
// Example: b := 'abcabc'.repeat(100).bytes(); compressed := deflate.compress(b)!; dump(compressed); assert compressed.len == 163
|
||||||
pub fn compress(data []u8) ![]u8 {
|
pub fn compress(data []u8) ![]u8 {
|
||||||
return compr.compress(data, 0)
|
return compr.compress(data, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// decompresses an array of bytes using deflate and returns the decompressed bytes in a new array
|
// decompresses an array of bytes using deflate and returns the decompressed bytes in a new array
|
||||||
// Example: decompressed := deflate.decompress(b)!
|
// Example: b := 'abcabc'.repeat(100).bytes(); compressed := deflate.compress(b)!; decompressed := deflate.decompress(compressed)!; assert b == decompressed
|
||||||
pub fn decompress(data []u8) ![]u8 {
|
pub fn decompress(data []u8) ![]u8 {
|
||||||
return compr.decompress(data, 0)
|
return compr.decompress(data, 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub:
|
||||||
}
|
}
|
||||||
|
|
||||||
// compresses an array of bytes using gzip and returns the compressed bytes in a new array
|
// compresses an array of bytes using gzip and returns the compressed bytes in a new array
|
||||||
// Example: compressed := gzip.compress(b, compression_level:4095)!
|
// Example: b := 'abcde'.repeat(1000).bytes(); cmprsd := gzip.compress(b, compression_level:4095)!; assert cmprsd.len == 47
|
||||||
// Note: compression_level 0~4095
|
// Note: compression_level 0~4095
|
||||||
pub fn compress(data []u8, params CompressParams) ![]u8 {
|
pub fn compress(data []u8, params CompressParams) ![]u8 {
|
||||||
if params.compression_level !in 0..4096 {
|
if params.compression_level !in 0..4096 {
|
||||||
|
@ -204,7 +204,7 @@ pub fn validate(data []u8, params DecompressParams) !GzipHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
// decompress an array of bytes using zlib and returns the decompressed bytes in a new array.
|
// decompress an array of bytes using zlib and returns the decompressed bytes in a new array.
|
||||||
// Example: decompressed := gzip.decompress(b)!
|
// Example: b := 'abcdef'.repeat(1000).bytes(); cmpr := gzip.compress(b)!; decmpr := gzip.decompress(cmpr)!; assert cmpr.len < b.len; assert b == decmpr
|
||||||
pub fn decompress(data []u8, params DecompressParams) ![]u8 {
|
pub fn decompress(data []u8, params DecompressParams) ![]u8 {
|
||||||
gzip_header := validate(data, params)!
|
gzip_header := validate(data, params)!
|
||||||
header_length := gzip_header.length
|
header_length := gzip_header.length
|
||||||
|
|
|
@ -3,14 +3,14 @@ module zlib
|
||||||
import compress as compr
|
import compress as compr
|
||||||
|
|
||||||
// compresses an array of bytes using zlib and returns the compressed bytes in a new array
|
// compresses an array of bytes using zlib and returns the compressed bytes in a new array
|
||||||
// Example: compressed := zlib.compress(b)!
|
// Example: b := 'abcdefgh'.repeat(1000).bytes(); cmpr := zlib.compress(b)!; assert cmpr.len < b.len; dc := zlib.decompress(cmpr)!; assert b == dc
|
||||||
pub fn compress(data []u8) ![]u8 {
|
pub fn compress(data []u8) ![]u8 {
|
||||||
// flags = TDEFL_WRITE_ZLIB_HEADER (0x01000)
|
// flags = TDEFL_WRITE_ZLIB_HEADER (0x01000)
|
||||||
return compr.compress(data, 0x01000)
|
return compr.compress(data, 0x01000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// decompresses an array of bytes using zlib and returns the decompressed bytes in a new array
|
// decompresses an array of bytes using zlib and returns the decompressed bytes in a new array
|
||||||
// Example: decompressed := zlib.decompress(b)!
|
// Example: b := 'abcdefgh'.repeat(1000).bytes(); cmpr := zlib.compress(b)!; assert cmpr.len < b.len; dc := zlib.decompress(cmpr)!; assert b == dc
|
||||||
pub fn decompress(data []u8) ![]u8 {
|
pub fn decompress(data []u8) ![]u8 {
|
||||||
// flags = TINFL_FLAG_PARSE_ZLIB_HEADER (0x1)
|
// flags = TINFL_FLAG_PARSE_ZLIB_HEADER (0x1)
|
||||||
return compr.decompress(data, 0x1)
|
return compr.decompress(data, 0x1)
|
||||||
|
|
|
@ -415,7 +415,7 @@ pub:
|
||||||
|
|
||||||
// compresses an array of bytes using zstd and returns the compressed bytes in a new array
|
// compresses an array of bytes using zstd and returns the compressed bytes in a new array
|
||||||
// extra compression parameters can be set by `params`
|
// extra compression parameters can be set by `params`
|
||||||
// Example: compressed := zstd.compress(b)!
|
// Example: b := 'abcdef'.repeat(1000).bytes(); cmpr := zstd.compress(b, compression_level: 10)!; assert cmpr.len < b.len; dc := zstd.decompress(cmpr)!; assert b == dc
|
||||||
pub fn compress(data []u8, params CompressParams) ![]u8 {
|
pub fn compress(data []u8, params CompressParams) ![]u8 {
|
||||||
dst_capacity := C.ZSTD_compressBound(data.len)
|
dst_capacity := C.ZSTD_compressBound(data.len)
|
||||||
check_error(dst_capacity)!
|
check_error(dst_capacity)!
|
||||||
|
@ -437,7 +437,7 @@ pub:
|
||||||
|
|
||||||
// decompresses an array of bytes using zstd and returns the decompressed bytes in a new array
|
// decompresses an array of bytes using zstd and returns the decompressed bytes in a new array
|
||||||
// extra decompression parameters can be set by `params`
|
// extra decompression parameters can be set by `params`
|
||||||
// Example: decompressed := zstd.decompress(b)!
|
// Example: b := 'abcdef'.repeat(1000).bytes(); cmpr := zstd.compress(b, compression_level: 10)!; assert cmpr.len < b.len; dc := zstd.decompress(cmpr)!; assert b == dc
|
||||||
pub fn decompress(data []u8, params DecompressParams) ![]u8 {
|
pub fn decompress(data []u8, params DecompressParams) ![]u8 {
|
||||||
dst_capacity := C.ZSTD_getFrameContentSize(data.data, frame_header_size_max)
|
dst_capacity := C.ZSTD_getFrameContentSize(data.data, frame_header_size_max)
|
||||||
if dst_capacity == content_size_unknown {
|
if dst_capacity == content_size_unknown {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue