mafintosh / tar-stream

tar-stream is a streaming tar parser and generator.
MIT License
408 stars 92 forks source link

Packing go binaries prevents entry callback from being called #64

Closed alexdavid closed 1 year ago

alexdavid commented 7 years ago

This is the strangest bug, but I've narrowed it down to go binaries. tar-stream seems to silently fail to add them. Anything else I add to the tar works fine.

Steps to reproduce:

Create file test.go:

package main

import "fmt"

func main() {
    fmt.Println("test")
}

Build go file:

$ go build test.go

Create file test.js:

var fs = require("fs");
var tar = require('tar-stream');

var fileName = "./test";
var pack = tar.pack();

fs.stat(fileName, function (err, stat) {
    if (err) {
        return console.log(err);
    }

    var packOptions = {
        mode: stat.mode,
        mtime: stat.mtime,
        name: 'test',
        size: stat.size
    };

    var rs = fs.createReadStream(fileName);
    var entry = pack.entry(packOptions, function (err) {
        console.log("This happens");
        pack.finalize();
    });
    console.log("We pipe the stream here and expect a callback...");
    return rs.pipe(entry);
});

Expected result: This happens gets logged and the pack is finalized. Actual result: This happens is never logged and pack is not finalized

mafintosh commented 7 years ago

could you share the binary file that is causing trouble? don't have go installed

alexdavid commented 7 years ago

Sorry for the late reply. Here's a link to the binary that is not behaving:

http://ipfs.io/ipfs/QmbWN6wpsuSwTrVNWX2nwGCM9ZqnPSzNYc3hUZACKANWiR

mgcrea commented 6 years ago

Not sure if this has anything to do with a go binary, similar code hangs for me as well as soon as I'm trying to pipe a readStream into an entry, in my case it's large mock buffer filled with 1.

mafintosh commented 6 years ago

@mgcrea can you share a test case?

diamondap commented 5 years ago

I ran into this issue as well while trying to extract Go binaries from a tar archive I had created with tar-stream. Further tests showed other large files, such as Mac .dmg files, had the same problem. I did find a workaround, which I posted here:

https://gist.github.com/diamondap/b6b36dd50e1e94e2bbe89a221124eb76

This issue does not seem to affect normal read streams, only PassThrough streams. All of the large binary files I tried to extract failed before this workaround, and they all work after.