ws-voxel: codecs/text/Nbt (NBT Java / Bedrock / network varint, SNBT parse + print, typed values), data/nbt, data/snbt
Shared change: codecs/compress/Deflate gains Deflate.peek(buf, off, len, n) (the first n inflated bytes of a gzip / zlib / raw stream, for sniffing gzip-wrapped NBT) through a backward-compatible prefix flag on Inflate.raw; gunzip's header parsing moved into a local helper both use. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
d3dbba500b
commit
512cbc3dc8
15 files changed
+2745
-26
No files matched your search
@@ -169,4 +169,23 @@ do
|
||||
end, samples, { mutations = 3, garbage = 300 })
|
||||
end
|
||||
|
||||
-- peek: the first bytes of a gzip / zlib / raw stream without inflating the rest
|
||||
do
|
||||
local src = buffer.create(100000)
|
||||
for i = 0, 99999 do
|
||||
buffer.writeu8(src, i, (i * 7 + (i // 97)) % 251)
|
||||
end
|
||||
local want = buffer.readstring(src, 0, 1000)
|
||||
for _, kind in { "gzip", "zlibCompress", "compress" } do
|
||||
local z = assert((Deflate :: any)[kind](src)) :: buffer
|
||||
local head = assert(Deflate.peek(z, nil, nil, 1000))
|
||||
t:check(buffer.len(head) <= 1000 and buffer.len(head) >= 1000 - 258, "peek " .. kind .. " size")
|
||||
t:eq(buffer.tostring(head), string.sub(want, 1, buffer.len(head)), "peek " .. kind .. " bytes")
|
||||
end
|
||||
local small = assert(Deflate.peek(assert(Deflate.gzip(buffer.fromstring("hello"))), nil, nil, 1000))
|
||||
t:eq(buffer.tostring(small), "hello", "peek a short stream")
|
||||
local _, e = Deflate.peek(buffer.fromstring("\31\139\8\0\0\0\0\0\0\3\255\255\255\255\255\255\255\255"), nil, nil, 10)
|
||||
t:check(e ~= nil, "peek bad data")
|
||||
end
|
||||
|
||||
t:done()
|
||||
Reference in new issue
Block a user