Example #1
0
Jaguar.prototype._parse     = function(name, callback) {
    var self        = this,
        wasError,
        
        streamFile  = fs.createReadStream(name),
        streamUnzip = zlib.createGunzip(),
        streamParse = tarStream.extract();
    
    streamParse.on('entry', function(header, stream, callback) {
        stream.on('end', function() {
            ++self._n;
            
            callback();
        });
        
        stream.resume();
    });
    
    streamParse.on('finish', function() {
        if (!wasError)
            callback();
    });
    
    pipe([
        streamFile,
        streamUnzip,
        streamParse
    ], function(error) {
        if (error) {
            wasError = true;
            callback(error);
        }
    });
};
Example #2
0
Jaguar.prototype._extract  = function() {
    var self        = this,
        from        = this._from,
        to          = this._to,
        streamFile  = fs.createReadStream(from),
        streamUnzip = zlib.createGunzip(),
        streamUntar = tar.extract(to);
        
    streamUntar.on('entry', function(header) {
        self._progress();
        self.emit('file', header.name);
    });
    
    streamUntar.on('finish', function() {
        self.emit('end');
    });
    
    pipe([
        streamFile,
        streamUnzip,
        streamUntar
    ], function(error) {
        if (error)
            self.emit('error', error);
    });
};
Example #3
0
 function pipeFiles(read, write, options, callback) {
     var gzip,
         streams         = [],
         isStrRead       = type.string(read),
         isStrWrite      = type.string(write),
         isFunc          = type.function(options),
         o               = {},
         optionsRead     = {
             bufferSize: 4 * 1024
         };
     
     if (isFunc)
         callback    = options;
     else 
         o           = options;
     
     assert(read, 'read could not be empty!');
     assert(write, 'write could not be empty!');
     assert(callback, 'callback could not be empty!');
     
     if (options.range)
         extendy(optionsRead, {
             start   : o.range.start,
             end     : o.range.end,
         });
     
     if (isStrRead)
         read        = fs.createReadStream(read, optionsRead);
     
     if (isStrWrite)
         write       = fs.createWriteStream(write);
     
     if (!o.gzip && !o.gunzip) {
         streams     = [read, write];
     }else {
         if (o.gzip)
             gzip    = zlib.createGzip();
         else
             gzip    = zlib.createGunzip();
         
         streams     = [read, gzip, write];
     }
     
     pipe(streams, options, callback);
 }
Example #4
0
Jaguar.prototype._pack = function() {
    var self        = this,
        from        = this._from,
        to          = this._to,
        
        streamFile  = typeof to === 'object' ?
            to : fs.createWriteStream(to),
        
        streamZip   = zlib.createGzip(),
        streamTar   = tar.pack(from, {
            entries : this._names,
            map: function(header) {
                self._progress();
                self.emit('file', header.name);
                
                return header;
            }
        });
        
        pipe([
            streamTar,
            streamZip,
            streamFile
        ], function(error) {
            if (error)
                self.emit('error', error);
            
            if (!self._abort)
                self.emit('end');
            else
                fs.unlink(to, function(error) {
                    if (error)
                        self.emit('error', error);
                    
                    self.emit('end');
                });
        });
};