Skip to content

Allow async "wrapper" callbacks #234

Description

@MannikJ

Please see this codesandbox:
(link removed)

Important part (shortened):

  return this.newParser()
     .namely("data")
     .endianess("little")
     .wrapped("data", {
       readUntil: "eof",
       wrapper: async (originalByteArray) => {
         try {
           const lzma = new LZMA();
           const result = await lzma.decompress(newByteArray);
           return Buffer.from(result.buffer);
         } catch (error) {
           console.error(error);
         }
       },
       // The parser to run on the decompressed data
       type: decompressedDataParser
     });

It should parse some custom file format which contains a LZMA-compressed portion which I would like to decompress within the wrapper function. The parser is not fully implemented, but it fails somewhere In the wrapping with

TypeError
imports[1].call(...).subarray is not a function

I've tinkered so much now, but I still can't get rid of this strange error and I don't know how to debug further. I thought it comes from a wrong return type of my wrapper function, but I am quite sure that this is not the problem. No matter what I return from the wrapper function, the error always occurs. It returns the same error message when I skip the whole processing and only return a new Buffer like this: return Buffer.from(new Uint8Array(32));
When I only use buffer instead of wrapped the parsing process runs through. So there is definitely some problem with the wrapping part.

I really hope you can help me with that!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions