Comments (3)
tar-fs should not call entry when that condition is true so its a bug there, have any easy repro, then i'll fix.
from tar-stream.
I assume the amount of files / size of files would also determine when this bug is hit. For different combinations of files and directories, some of them would error, some wouldn't.
To reproduce:
Here is the file system I was using:
davew@chud:~/test_files$ ls
a b c
davew@chud:~/test_files$ du -h
1.1G ./c
1.1G ./a
1.1G ./b
3.2G .
davew@chud:~/test_files/$ find . | wc -l
1540
Files created in each a b c
directory with:
for n in {1..512}; do dd if=/dev/urandom of=file$( printf %03d "$n" ) bs=4248 count=512; done
Here is the MRE:
const tar = require('tar-fs');
const { pipeline } = require('node:stream/promises');
const express = require('express');
const app = express();
async function streamData(_, res) {
const tarStream = tar.pack("test_files");
const work = pipeline(tarStream, res);
try {
await work;
} catch (err) {
console.log("Stream error:", err.code);
}
}
app.post("*", streamData);
app.listen(33333, () => {
console.log(`Server listening on port: ${33333}`);
});
Here is the call (made from another machine) obviously, this would work if I added -o filename
:
> curl -vvv -H 'Content-Type: application/json' -X POST http://172.16.32.12:33333
* Trying 172.16.32.12:33333...
* Connected to 172.16.32.12 (172.16.32.12) port 33333
> POST / HTTP/1.1
> Host: 172.16.32.12:33333
> User-Agent: curl/8.4.0
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Date: Wed, 07 Feb 2024 14:18:51 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked
<
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
* Failure writing output to destination
* Failed reading the chunked-encoded stream
* Closing connection
And the result:
davew@chud:~/test_files$ node test.js
Server listening on port: 33333
Stream error: ERR_STREAM_PREMATURE_CLOSE
/home/davew/test_get_files/node_modules/tar-stream/pack.js:138
if (this._finalized || this.destroying) throw new Error('already finalized or destroyed')
^
Error: already finalized or destroyed
at Pack.entry (/home/davew/test_get_files/node_modules/tar-stream/pack.js:138:51)
at onstat (/home/davew/test_get_files/node_modules/tar-fs/index.js:70:19)
at /home/davew/test_get_files/node_modules/tar-fs/index.js:353:9
at FSReqCallback.oncomplete (node:fs:189:23)
Node.js v20.9.0
davew@chud:~/test_files$
If I delete one of the folders (or remove some files), it works fine:
Server listening on port: 33333
Stream error: ERR_STREAM_PREMATURE_CLOSE
Thanks
from tar-stream.
I have fixed this in my test environment with:
function onstat (err, filename, stat) {
if (pack.destroyed) return
Whether this is the right way to fix it or not ¯\(ツ)/¯
Of note, I did go down the rabbit hole of nodejs/node#7629 where I see you were involved ha
from tar-stream.
Related Issues (20)
- all entry name are paxheader HOT 2
- "Invalid tar header: unknown format." from valid tar file, IANA tz database HOT 5
- Tar file is corrupted when using single File larger than 8 GB - tar-fs HOT 1
- Packing files at the root HOT 1
- File corrupted when combining extract with gzip HOT 2
- unable to use stream.pipeline() HOT 1
- doesn't work with HOT 2
- skipping on entry, header errors HOT 1
- zero-sized files in tarballs do not call `end` handler HOT 2
- error handling issue HOT 3
- Add browser support HOT 12
- Error: Writable stream closed prematurely HOT 1
- Missing fast-fifo dependency HOT 2
- Using tar stream in the browser HOT 8
- Error: Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped? HOT 4
- create entry with base-256 size HOT 3
- Invalid tar header: unknown format. (for ExtendedName)
- Is it possible to return raw file offsets from within the tar? HOT 6
- Benchmarks not maintained in tar-fs
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 tar-stream.