extracting a github tarball archive using streams

1,450 views
Skip to first unread message

Glenn Scott

unread,
Apr 25, 2013, 11:40:40 PM4/25/13
to nod...@googlegroups.com
I'm missing something obvious... when I download a tarball from Github and attempt to stream it to node-tar, the Extract method tells me I have an invalid tar file.  Any ideas?

var tar     = require( 'tar' )
  , request = require( 'request' )
  , UA      = 'test/1.0'
  , options = { headers: { "User-Agent": UA } }
  , fs      = require('fs')


// this works

  request( uri, options )
    .pipe( fs.createWriteStream( 'out.tar' ) )
    .on( "end", function() {
      console.log( 'done' )
    })
    .on( "error", function( e ) {
      console.log( e )
    })


/*

  // this doesn't work ('Error: invalid tar file')

  request( uri, options )
    .pipe( tar.Extract( { path: __dirname + '/extract' } ) )
    .on( "end", function() {
      console.log( 'done' )
    })
    .on( "error", function( e ) {
      console.log( e )
    })

*/


Ryan Schmidt

unread,
Apr 25, 2013, 11:43:57 PM4/25/13
to nod...@googlegroups.com

On Apr 25, 2013, at 22:40, Glenn Scott wrote:

> I'm missing something obvious... when I download a tarball from Github and attempt to stream it to node-tar, the Extract method tells me I have an invalid tar file. Any ideas?

Tarballs from github are gzip-compressed. Does your code handle that?


Martin Cooper

unread,
Apr 26, 2013, 12:18:16 AM4/26/13
to nod...@googlegroups.com
Right, because as Ryan mentioned, a tarball isn't a tar file, it's a .tar.gz file. You need something like:

    .pipe(zlib.Unzip())
    .pipe( tar.Extract( { path: __dirname + '/extract' } ) )

(with the requisite error handling, of course).

--
Martin Cooper

 
*/


--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Glenn Scott

unread,
Apr 26, 2013, 12:39:12 AM4/26/13
to nod...@googlegroups.com
Thanks all, of course zlib.Unzip() did the trick.

Joan R.

unread,
Mar 1, 2016, 11:10:43 AM3/1/16
to nodejs
Can you please post a complete example?
Reply all
Reply to author
Forward
0 new messages