Skip to content

refactor: adds optionalReadLimit params#249

Merged
Mzack9999 merged 2 commits intomainfrom
dwisiswant0/refactor/adds-optionalReadLimit-params
May 14, 2025
Merged

refactor: adds optionalReadLimit params#249
Mzack9999 merged 2 commits intomainfrom
dwisiswant0/refactor/adds-optionalReadLimit-params

Conversation

@dwisiswant0
Copy link
Copy Markdown
Member

@dwisiswant0 dwisiswant0 commented May 14, 2025

to the following DLS functions:

  • gzip_decode
  • zlib_decode, and
  • inflate

updated signatures:

-	gzip_decode(arg1 interface{}) interface{}
+	gzip_decode(data string, optionalReadLimit int) string

-	inflate(arg1 interface{}) interface{}
+	inflate(data string, optionalReadLimit int) string

-	zlib_decode(arg1 interface{}) interface{}
+	zlib_decode(data string, optionalReadLimit int) string

tests:

Test: zlib_decode(hex_decode("789cf248cdc9c907040000ffff058c01f5"))
Output: "Hello"
Test: gzip_decode(hex_decode("1f8b08000000000000fff248cdc9c907040000ffff8289d1f705000000"))
Output: "Hello"
Test: inflate(hex_decode("f248cdc9c907040000ffff"))
Output: "Hello"

Test: zlib_decode(hex_decode("789cf248cdc9c907040000ffff058c01f5"), 100)
Output: "Hello"
Test: gzip_decode(hex_decode("1f8b08000000000000fff248cdc9c907040000ffff8289d1f705000000"), 100)
Output: "Hello",
Test: inflate(hex_decode("f248cdc9c907040000ffff"), 100)
Output: "Hello"

Test: zlib_decode(hex_decode("789cf248cdc9c907040000ffff058c01f5"), 4)
Output: "Hell"
Test: gzip_decode(hex_decode("1f8b08000000000000fff248cdc9c907040000ffff8289d1f705000000"), 4)
Output: "Hell"
Test: inflate(hex_decode("f248cdc9c907040000ffff"), 4)
Output: "Hell"

closes #247

to these following DLS functions:
* gzip_decode
* zlib_decode, and
* inflate

Signed-off-by: Dwi Siswanto <git@dw1.io>
Signed-off-by: Dwi Siswanto <git@dw1.io>
@HaimLC
Copy link
Copy Markdown

HaimLC commented May 14, 2025

Does io.EOF the same behavior as io.ErrUnexpectedEOF in #248 ?

@dwisiswant0
Copy link
Copy Markdown
Member Author

Does io.EOF the same behavior as io.ErrUnexpectedEOF in #248 ?

no, but because we’re using io.LimitReader, the reader will just return whatever data is available and then hit EOF. it won’t throw an error unless we switch to io.ReadFull, which expects a specific $$N$$ of data (e.g., fixed length block). if the input ends unexpectedly (corrupted or truncated or cut off), and the stream finishes before reaching that $$N$$ length, then it would return io.ErrUnexpectedEOF. see the tests. hope that clears things up!

@Mzack9999 Mzack9999 merged commit 8f050a4 into main May 14, 2025
7 checks passed
@Mzack9999 Mzack9999 deleted the dwisiswant0/refactor/adds-optionalReadLimit-params branch May 14, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Support partial gzip_decode

3 participants