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.
This commit is contained in:
1 parent
de4f14a343
commit
998177e5ab
15 files changed
+2745
-26
No files matched your search
@@ -62,9 +62,10 @@ local function grow(out: buffer, op: number, need: number): (buffer, number)
|
||||
end
|
||||
|
||||
-- Inflate src[start, endpos) into a buffer. cap: initial output capacity; exact: true = the output must fit in
|
||||
-- cap bytes (an error otherwise), false = grow as needed.
|
||||
-- cap bytes (an error otherwise), false = grow as needed. prefix (with exact): stop at cap instead of failing and
|
||||
-- return what was inflated so far (at most cap bytes; Deflate.peek, for sniffing).
|
||||
-- Returns out, outLen, consumedEnd (the input offset just past the final block) or nil, message.
|
||||
function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, exact: boolean): (buffer?, any, number?)
|
||||
function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, exact: boolean, prefix: boolean?): (buffer?, any, number?)
|
||||
local out = bcreate(cap)
|
||||
local op = 0
|
||||
local pos = start
|
||||
@@ -123,6 +124,9 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
end
|
||||
if op + n > cap then
|
||||
if exact then
|
||||
if prefix then
|
||||
return out, op, pos
|
||||
end
|
||||
return nil, "output larger than expected"
|
||||
end
|
||||
out, cap = grow(out, op, op + n)
|
||||
@@ -295,6 +299,9 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
if sym < 256 then
|
||||
if op >= cap then
|
||||
if exact then
|
||||
if prefix then
|
||||
return out, op, pos
|
||||
end
|
||||
return nil, "output larger than expected"
|
||||
end
|
||||
out, cap = grow(out, op, op + 1)
|
||||
@@ -388,6 +395,9 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
end
|
||||
if op + len > cap then
|
||||
if exact then
|
||||
if prefix then
|
||||
return out, op, pos
|
||||
end
|
||||
return nil, "output larger than expected"
|
||||
end
|
||||
out, cap = grow(out, op, op + len)
|
||||
|
||||
Reference in new issue
Block a user