GithubHelp home page GithubHelp logo

Comments (6)

sile avatar sile commented on June 19, 2024 2

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.

sile avatar sile commented on June 19, 2024

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.

Phill030 avatar Phill030 commented on June 19, 2024

@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
chrome_0hr6aTq6w8

from libflate.

Phill030 avatar Phill030 commented on June 19, 2024

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.

Phill030 avatar Phill030 commented on June 19, 2024

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.

sile avatar sile commented on June 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.