Giter Site home page Giter Site logo

fastfile's People

Contributors

dependabot[bot] avatar jbaylina avatar lispc avatar obrezhniev avatar phated avatar xavi-pinsach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fastfile's Issues

TypeError: Cannot read property 'buff' of undefined

I'm using fastfile to parse a large .tar file. At first, everything seems to work, but some way in, the following error is thrown:

TypeError: Cannot read property 'buff' of undefined
   at FastFile.readToBuffer (C:\dev\rhubarb-2-poc\node_modules\fastfile\build\main.cjs:316:58)       
   at async readTarFile (C:\dev\rhubarb-2-poc\src\utils\read-tar-file.ts:23:7)

Here's my code. Given that the error only occurs after quite some iterations, I don't have a better way of reproducing the problem.

import { readExisting } from 'fastfile';
import { utf8ArrayToString } from './utf8-array-to-string';

interface TarFileEntry {
  filePath: string;
  fileSize: number;
  getFileBytes(): Promise<Uint8Array>;
}

export async function* readTarFile(
  tarFilePath: string,
): AsyncIterableIterator<TarFileEntry> {
  const file = await readExisting(tarFilePath);

  try {
    const blockSize = 512;
    const headerBytes = new Uint8Array(blockSize);
    const filePathBytes = new Uint8Array(headerBytes.buffer, 0, 100);
    const fileSizeBytes = new Uint8Array(headerBytes.buffer, 124, 12);

    let zeroBlockCount = 0;
    while (true) {
      await file.readToBuffer(headerBytes, 0, blockSize); // THIS LINE THROWS AFTER SOME ITERATIONS
      if (headerBytes[0] === 0) {
        zeroBlockCount++;
        // Two consecutive zero blocks indicate end of file
        if (zeroBlockCount === 2) return;
      } else {
        zeroBlockCount = 0;
      }

      const filePath = utf8ArrayToString(filePathBytes);
      const fileSize = parseInt(utf8ArrayToString(fileSizeBytes), 8);
      if (fileSize === 0) continue; // directory

      const bufferSize = Math.ceil(fileSize / blockSize) * blockSize;
      const bufferPosition = file.pos;
      console.log(filePath);
      yield {
        filePath,
        fileSize,
        async getFileBytes() {
          if (file.pos !== bufferPosition) {
            throw new Error('Cannot read file once iteration has continued.');
          }

          const bufferBytes = new Uint8Array(bufferSize);
          await file.readToBuffer(bufferBytes, 0, bufferSize);
          return new Uint8Array(bufferBytes.buffer, 0, fileSize);
        },
      };

      file.pos = bufferPosition + bufferSize;
    }
  } finally {
    await file.close();
  }
}

Bun integration: error with `fd.stat()`

Bun is a fast runtime for JS, and I think it would greatly speed-up the development process if Snarkjs had supported it. When we try to prove something via SnarkJS using Bun (v0.1.14, latest at the time of writing) we get the following error:

❯ bun index.js
 5 |     cacheSize = cacheSize || 4096*64;
 6 |     if (typeof openFlags !== "number" && ["w+", "wx+", "r", "ax+", "a+"].indexOf(openFlags) <0)
 7 |         throw new Error("Invalid open option");
 8 |     const fd =await fs.promises.open(fileName, openFlags);
 9 | 
10 |     const stats = await fd.stat();
                            ^
TypeError: fd.stat is not a function. (In 'fd.stat()', 'fd.stat' is undefined)
      at .../node_modules/fastfile/src/osfile.js:10:24

I would like to open an issue on Bun's side for support for whatever is being used here, could you please explain what fd.stat does for this purpose?

'Too many promises' error when reading a large file

RangeError: Too many elements passed to Promise.all
at Function.all ()
at FastFile._triggerLoad (/home/ec2-user/snarkjs/node_modules/fastfile/build/main.cjs:167:17)
at FastFile.readToBuffer (/home/ec2-user/snarkjs/node_modules/fastfile/build/main.cjs:305:14)
at processSectionPower (/home/ec2-user/snarkjs/build/cli.cjs:3069:29)
at async processSection (/home/ec2-user/snarkjs/build/cli.cjs:3044:13)
at async prepareSection (/home/ec2-user/snarkjs/build/cli.cjs:3019:9)
at async Object.powersOfTauPrepareSection [as action] (/home/ec2-user/snarkjs/build/cli.cjs:13428:12)
at async clProcessor (/home/ec2-user/snarkjs/build/cli.cjs:454:27)

Node.js v20.11.1

See also snarkjs issue #435

[email protected] seems to have falowing error Note that on snarkjs that uses [email protected] does not have this issue

./node_modules/fastfile/src/fastfile.js
Can't import the named export 'O_TRUNC' (imported as 'O_TRUNC') from default-exporting module (only default export is available)

Import trace for requested module:
./node_modules/snarkjs/src/powersoftau_export_challenge.js
./node_modules/snarkjs/src/powersoftau.js
./node_modules/snarkjs/main.js

./node_modules/fastfile/src/fastfile.js
Can't import the named export 'O_CREAT' (imported as 'O_CREAT') from default-exporting module (only default export is available)

Import trace for requested module:
./node_modules/snarkjs/src/powersoftau_export_challenge.js
./node_modules/snarkjs/src/powersoftau.js
./node_modules/snarkjs/main.js

./node_modules/fastfile/src/fastfile.js
Can't import the named export 'O_RDWR' (imported as 'O_RDWR') from default-exporting module (only default export is available)

Import trace for requested module:
./node_modules/snarkjs/src/powersoftau_export_challenge.js
./node_modules/snarkjs/src/powersoftau.js
./node_modules/snarkjs/main.js

./node_modules/fastfile/src/fastfile.js
Can't import the named export 'O_TRUNC' (imported as 'O_TRUNC') from default-exporting module (only default export is available)

Import trace for requested module:
./node_modules/snarkjs/src/powersoftau_export_challenge.js
./node_modules/snarkjs/src/powersoftau.js
./node_modules/snarkjs/main.js

./node_modules/fastfile/src/fastfile.js
Can't import the named export 'O_CREAT' (imported as 'O_CREAT') from default-exporting module (only default export is available)

Import trace for requested module:
./node_modules/snarkjs/src/powersoftau_export_challenge.js
./node_modules/snarkjs/src/powersoftau.js
./node_modules/snarkjs/main.js

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.