mafintosh / tar-stream

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

Invalid tar header: unknown format. (for ExtendedName) #161

Open jeroen opened 9 months ago

jeroen commented 9 months ago

The attached tar.gz was created with the default settings using gnutar on a directory containing a large filename. It seems to automatically have switched on extended file attributes (the tar contains a file ExtendedName).

LHsampling_0.1.0.tar.gz

It errors when trying to extract with tar-stream: Invalid tar header: unknown format.

A workaround is to use var extract = tar.extract({allowUnknownFormat:true});


var fs = require('fs');
var tar = require('tar-stream');
var gunzip = require('gunzip-maybe');

tar_list('./LHsampling_0.1.0.tar.gz')

function tar_list(path){
  var input = fs.createReadStream(path);
  var extract = tar.extract();
  extract.on('entry', function(header, file_stream, next_entry) {
    console.log(header.name)
    next_entry();
    file_stream.resume();
  });
  extract.on('finish', function() {
    console.log("Done!")
  });
  extract.on('error', function(err) {
    console.log("ERROR", err)
  });
  return input.pipe(gunzip()).pipe(extract);
}