Comments (6)
Added Decoder::unread_decoded_data()
in #72.
You can retrieve partial decoded data using the method even when the decoding process has failed as follows:
let encoded_data = [
120, 218, 251, 255, 207, 144, 193, 138, 193, 151, 161, 146, 33, 143, 33, 149, 161, 156,
161, 24, 72, 38, 51, 148, 48, 100, 50, 228, 3, 69, 120, 25, 184, 24,
];
let mut decoder = Decoder::new(&encoded_data[..]).unwrap();
let mut buf = Vec::new();
let result = decoder.read_to_end(&mut buf);
assert!(result.is_err());
buf.extend_from_slice(decoder.unread_decoded_data());
let decoded_data = [
255, 254, 49, 0, 58, 0, 77, 0, 121, 0, 110, 0, 101, 0, 119, 0, 115, 0, 101, 0, 99, 0,
116, 0, 105, 0, 111, 0, 110, 0, 13, 0, 10,
];
assert_eq!(buf, decoded_data);
from libflate.
Could you share your TypeScript code that was able to decode the data?
I tried decoding the data using Node.js but it failed as follows:
> require('zlib')
> zlib.inflateSync(new Uint8Array( [120, 218, 251, 255, 207, 144, 193, 138, 193, 151, 161, 146, 33, 143, 33, 149, 161, 156, 161, 24, 72, 38, 51, 148, 48, 100, 50, 228, 3, 69, 120, 25, 184, 24]))
Uncaught Error: unexpected end of file
at Zlib.zlibOnError [as onerror] (node:zlib:189:17)
at Zlib.callbackTrampoline (node:internal/async_hooks:130:17)
at processChunkSync (node:zlib:457:12)
at zlibBufferSync (node:zlib:178:12)
at Object.syncBufferWrapper [as inflateSync] (node:zlib:792:14)
at REPL41:1:6
at Script.runInThisContext (node:vm:128:12)
at REPLServer.defaultEval (node:repl:570:29)
at bound (node:domain:433:15) {
errno: -5,
code: 'Z_BUF_ERROR'
}
I tried with Python3 too, but it got the same error:
> import zlib
> >>> x = [120, 218, 251, 255, 207, 144, 193, 138, 193, 151, 161, 146, 33, 143, 33, 149, 161, 156, 161, 24, 72, 38, 51, 148, 48, 100, 50, 228, 3, 69, 120, 25, 184, 24]
>>> y = b''.join(x.to_bytes(1, byteorder='big') for x in x)
>>> zlib.decompress(y)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
zlib.error: Error -5 while decompressing data: incomplete or truncated stream
from libflate.
@sile Sure: this is my TypeScript code:
import * as zlib from "zlib";
const inflatedBuffer = zlib.inflateSync(buffer, { finishFlush: zlib.constants.Z_FULL_FLUSH });
This is how I was able to solve your unexpected end of file
error
from libflate.
It should return
ff fe 31 00 3a 00 4d 00 79 00 6e 00 65 00 77 00 73 00 65 00 63 00 74 00 69 00 6f 00 6e 00 0d 00 0a
or
1:Mynewsection
if done right
from libflate.
Using a 4 year old crate called inflate
works, using the inflate_bytes_zlib
method so you may want to have a look in that :D I hope this can be implemented/fixed
from libflate.
Thank you.
After some investigation, it seems that the input data is somewhat corrupted, so unexpected EOF error is raised without Z_FULL_FLUSH
option ( Z_FULL_FLUSH
option seems to force to return decoded data even when the decoding process isn't completed).
I'm not sure that libflate
should fully support this case. But, anyway, I'm going to consider if there is a reasonable way to retrieve incomplete decoding data from the decoder instance.
from libflate.
Related Issues (20)
- Decoder::read_non_compressed_block() is unsound HOT 4
- Decoder may expose contents of uninitialized memory in the output HOT 5
- Use-after-free on panic in client code HOT 4
- Remove byteorder-dependency HOT 1
- Possible concurrency issue during deflate on libflate 0.1.25 HOT 8
- Convenience functions? HOT 1
- btype 0x11 of DEFLATE is reserved(error) value HOT 1
- LZ77 compressor as a separate crate? HOT 3
- libflate 1.0.0 is on crates.io, but not here HOT 1
- Encoder panic on specific input data... HOT 1
- Compression level HOT 5
- UnexpectedEof encountered when decompressing data HOT 4
- Streaming data extensions HOT 4
- LZ77 decoder? HOT 2
- libflate::gzip::Decoder::read does not handle zero-length buffer properly HOT 2
- UB in the public safe API - where to report? HOT 4
- Panic in `bug` when parsing malformed file HOT 4
- GzDecoder seem decode incorrect HOT 9
- Error while decoding just encoded data HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libflate.