Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use chunked streams to read files #39

Open
badsyntax opened this issue Feb 8, 2022 · 0 comments
Open

Use chunked streams to read files #39

badsyntax opened this issue Feb 8, 2022 · 0 comments

Comments

@badsyntax
Copy link
Owner

Richard, just a thing for the future to you think about it.
When I hash files, i create a fs.createReadStream(path) and do it on chunks, using .on('data', (data) => hash.update(data))
the thing is that on('error') i can handle it properly.
The most common error is while reading the file, the file gets deleted or changed.
So this is a common thing to do, handle the EBUSY when it happens

.on('error', (err) => {
        let endTime = new Date().getTime();
        const time = endTime - startTime;
        const seconds = time / 1000;
        if (err.message.indexOf('EBUSY') !== -1) {
          resolve({
            tipo: 'ERROR_EBUSY',
            timeSpent: seconds,
            path: path,
          });
        }

Originally posted by @leopucci in #32 (comment)

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

No branches or pull requests

1 participant