aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tar-stream
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-24 15:10:37 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-24 15:11:17 +0200
commit7a3df06eb573d36142bd1a8e03c5ce8752d300b3 (patch)
tree70bfaea8884c374876f607774850a3a51c0cb381 /node_modules/tar-stream
parentaca1143cb9eed16cf37f04e475e4257418dd18ac (diff)
downloadwallet-core-7a3df06eb573d36142bd1a8e03c5ce8752d300b3.tar.xz
fix build issues and add typedoc
Diffstat (limited to 'node_modules/tar-stream')
-rw-r--r--node_modules/tar-stream/README.md39
-rw-r--r--node_modules/tar-stream/extract.js2
-rw-r--r--node_modules/tar-stream/headers.js27
-rw-r--r--node_modules/tar-stream/package.json2
4 files changed, 54 insertions, 16 deletions
diff --git a/node_modules/tar-stream/README.md b/node_modules/tar-stream/README.md
index 8d0a094b1..96abbca1b 100644
--- a/node_modules/tar-stream/README.md
+++ b/node_modules/tar-stream/README.md
@@ -9,6 +9,7 @@ npm install tar-stream
```
[![build status](https://secure.travis-ci.org/mafintosh/tar-stream.png)](http://travis-ci.org/mafintosh/tar-stream)
+[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)
## Usage
@@ -50,18 +51,18 @@ pack.pipe(process.stdout)
## Extracting
-To extract a stream use `tar.extract()` and listen for `extract.on('entry', header, stream, callback)`
+To extract a stream use `tar.extract()` and listen for `extract.on('entry', (header, stream, next) )`
``` js
var extract = tar.extract()
-extract.on('entry', function(header, stream, callback) {
+extract.on('entry', function(header, stream, next) {
// header is the tar header
// stream is the content body (might be an empty stream)
// call next when you are done with this entry
stream.on('end', function() {
- callback() // ready for next entry
+ next() // ready for next entry
})
stream.resume() // just auto drain the stream
@@ -74,6 +75,8 @@ extract.on('finish', function() {
pack.pipe(extract)
```
+The tar archive is streamed sequentially, meaning you **must** drain each entry's stream as you get them or else the main extract stream will receive backpressure and stop reading.
+
## Headers
The header object using in `entry` should contain the following properties.
@@ -126,6 +129,36 @@ oldTarballStream.pipe(extract)
pack.pipe(newTarballStream)
```
+## Saving tarball to fs
+
+
+``` js
+var fs = require('fs')
+var tar = require('tar-stream')
+
+var pack = tar.pack() // pack is a streams2 stream
+var path = 'YourTarBall.tar'
+var yourTarball = fs.createWriteStream(path)
+
+// add a file called YourFile.txt with the content "Hello World!"
+pack.entry({name: 'YourFile.txt'}, 'Hello World!', function (err) {
+ if (err) throw err
+ pack.finalize()
+})
+
+// pipe the pack stream to your file
+pack.pipe(yourTarball)
+
+yourTarball.on('close', function () {
+ console.log(path + ' has been written')
+ fs.stat(path, function(err, stats) {
+ if (err) throw err
+ console.log(stats)
+ console.log('Got file info successfully!')
+ })
+})
+```
+
## Performance
[See tar-fs for a performance comparison with node-tar](https://github.com/mafintosh/tar-fs/blob/master/README.md#performance)
diff --git a/node_modules/tar-stream/extract.js b/node_modules/tar-stream/extract.js
index 6b3b9bf44..8be2a472c 100644
--- a/node_modules/tar-stream/extract.js
+++ b/node_modules/tar-stream/extract.js
@@ -166,7 +166,7 @@ var Extract = function (opts) {
self._locked = true
- if (!header.size) {
+ if (!header.size || header.type === 'directory') {
self._parse(512, onheader)
self.emit('entry', header, emptyStream(self, offset), onunlock)
return
diff --git a/node_modules/tar-stream/headers.js b/node_modules/tar-stream/headers.js
index 8c75edcc4..8aab8b561 100644
--- a/node_modules/tar-stream/headers.js
+++ b/node_modules/tar-stream/headers.js
@@ -1,4 +1,5 @@
var ZEROS = '0000000000000000000'
+var SEVENS = '7777777777777777777'
var ZERO_OFFSET = '0'.charCodeAt(0)
var USTAR = 'ustar\x0000'
var MASK = parseInt('7777', 8)
@@ -92,7 +93,8 @@ var cksum = function (block) {
var encodeOct = function (val, n) {
val = val.toString(8)
- return ZEROS.slice(0, n - val.length) + val + ' '
+ if (val.length > n) return SEVENS.slice(0, n) + ' '
+ else return ZEROS.slice(0, n - val.length) + val + ' '
}
/* Copied from the node-tar repo and modified to meet
@@ -130,10 +132,13 @@ function parse256 (buf) {
return positive ? sum : -1 * sum
}
-var decodeOct = function (val, offset) {
+var decodeOct = function (val, offset, length) {
+ val = val.slice(offset, offset + length)
+ offset = 0
+
// If prefixed with 0x80 then parse as a base-256 integer
if (val[offset] & 0x80) {
- return parse256(val.slice(offset, offset + 8))
+ return parse256(val)
} else {
// Older versions of tar can prefix with spaces
while (offset < val.length && val[offset] === 32) offset++
@@ -239,17 +244,17 @@ exports.decode = function (buf) {
var typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET
var name = decodeStr(buf, 0, 100)
- var mode = decodeOct(buf, 100)
- var uid = decodeOct(buf, 108)
- var gid = decodeOct(buf, 116)
- var size = decodeOct(buf, 124)
- var mtime = decodeOct(buf, 136)
+ var mode = decodeOct(buf, 100, 8)
+ var uid = decodeOct(buf, 108, 8)
+ var gid = decodeOct(buf, 116, 8)
+ var size = decodeOct(buf, 124, 12)
+ var mtime = decodeOct(buf, 136, 12)
var type = toType(typeflag)
var linkname = buf[157] === 0 ? null : decodeStr(buf, 157, 100)
var uname = decodeStr(buf, 265, 32)
var gname = decodeStr(buf, 297, 32)
- var devmajor = decodeOct(buf, 329)
- var devminor = decodeOct(buf, 337)
+ var devmajor = decodeOct(buf, 329, 8)
+ var devminor = decodeOct(buf, 337, 8)
if (buf[345]) name = decodeStr(buf, 345, 155) + '/' + name
@@ -262,7 +267,7 @@ exports.decode = function (buf) {
if (c === 8 * 32) return null
// valid checksum
- if (c !== decodeOct(buf, 148)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?')
+ if (c !== decodeOct(buf, 148, 8)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?')
return {
name: name,
diff --git a/node_modules/tar-stream/package.json b/node_modules/tar-stream/package.json
index 82518740f..5e2bd7b64 100644
--- a/node_modules/tar-stream/package.json
+++ b/node_modules/tar-stream/package.json
@@ -1,6 +1,6 @@
{
"name": "tar-stream",
- "version": "1.5.2",
+ "version": "1.5.4",
"description": "tar-stream is a streaming tar parser and generator and nothing else. It is streams2 and operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.",
"author": "Mathias Buus <mathiasbuus@gmail.com>",
"engines": {