1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v: forbid function parameter names, shadowing imported module names (#17210)

This commit is contained in:
ChAoS_UnItY
2023-02-09 02:37:04 +08:00
committed by GitHub
parent c16549b6fd
commit 404a9aa442
45 changed files with 381 additions and 230 deletions

View File

@ -1,15 +1,15 @@
module deflate
import compress
import compress as compr
// compresses an array of bytes using deflate and returns the compressed bytes in a new array
// Example: compressed := deflate.compress(b)?
pub fn compress(data []u8) ![]u8 {
return compress.compress(data, 0)
return compr.compress(data, 0)
}
// decompresses an array of bytes using deflate and returns the decompressed bytes in a new array
// Example: decompressed := deflate.decompress(b)?
pub fn decompress(data []u8) ![]u8 {
return compress.decompress(data, 0)
return compr.decompress(data, 0)
}

View File

@ -3,13 +3,13 @@
module gzip
import compress
import compress as compr
import hash.crc32
// compresses an array of bytes using gzip and returns the compressed bytes in a new array
// Example: compressed := gzip.compress(b)?
pub fn compress(data []u8) ![]u8 {
compressed := compress.compress(data, 0)!
compressed := compr.compress(data, 0)!
// header
mut result := [
u8(0x1f), // magic numbers (1F 8B)
@ -139,7 +139,7 @@ pub fn decompress(data []u8, params DecompressParams) ![]u8 {
gzip_header := validate(data, params)!
header_length := gzip_header.length
decompressed := compress.decompress(data[header_length..data.len - 8], 0)!
decompressed := compr.decompress(data[header_length..data.len - 8], 0)!
length_expected := (u32(data[data.len - 4]) << 24) | (u32(data[data.len - 3]) << 16) | (u32(data[data.len - 2]) << 8) | data[data.len - 1]
if params.verify_length && decompressed.len != length_expected {
return error('length verification failed, got ${decompressed.len}, expected ${length_expected}')

View File

@ -1,17 +1,17 @@
module zlib
import compress
import compress as compr
// compresses an array of bytes using zlib and returns the compressed bytes in a new array
// Example: compressed := zlib.compress(b)?
pub fn compress(data []u8) ![]u8 {
// flags = TDEFL_WRITE_ZLIB_HEADER (0x01000)
return compress.compress(data, 0x01000)
return compr.compress(data, 0x01000)
}
// decompresses an array of bytes using zlib and returns the decompressed bytes in a new array
// Example: decompressed := zlib.decompress(b)?
pub fn decompress(data []u8) ![]u8 {
// flags = TINFL_FLAG_PARSE_ZLIB_HEADER (0x1)
return compress.decompress(data, 0x1)
return compr.decompress(data, 0x1)
}