tar 2.0.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ The ISC License
2
+ Copyright (c) Isaac Z. Schlueter and Contributors
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
7
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
8
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
9
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
10
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
11
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
12
+ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -22,7 +22,9 @@ stream.
22
22
  This only works with directories, it does not work with individual files.
23
23
 
24
24
  The optional `properties` object are used to set properties in the tar
25
- 'Global Extended Header'.
25
+ 'Global Extended Header'. If the `fromBase` property is set to true,
26
+ the tar will contain files relative to the path passed, and not with
27
+ the path included.
26
28
 
27
29
  ### tar.Extract([options])
28
30
 
package/lib/entry.js CHANGED
@@ -24,6 +24,7 @@ function Entry (header, extended, global) {
24
24
  this._ending = false
25
25
  this._ended = false
26
26
  this._remaining = 0
27
+ this._abort = false
27
28
  this._queue = []
28
29
  this._index = 0
29
30
  this._queueLen = 0
@@ -209,5 +210,11 @@ Entry.prototype._setProps = function () {
209
210
  this._remaining = props.size
210
211
  }
211
212
 
213
+ // the parser may not call write if _abort is true.
214
+ // useful for skipping data from some files quickly.
215
+ Entry.prototype.abort = function(){
216
+ this._abort = true
217
+ }
218
+
212
219
  Entry.prototype.warn = fstream.warn
213
220
  Entry.prototype.error = fstream.error
package/lib/extract.js CHANGED
@@ -88,7 +88,7 @@ inherits(Extract, tar.Parse)
88
88
 
89
89
  Extract.prototype._streamEnd = function () {
90
90
  var me = this
91
- if (!me._ended) me.error("unexpected eof")
91
+ if (!me._ended || me._entry) me.error("unexpected eof")
92
92
  me._fst.end()
93
93
  // my .end() is coming later.
94
94
  }
package/lib/pack.js CHANGED
@@ -131,7 +131,12 @@ Pack.prototype._process = function () {
131
131
  // in the tarball to use. That way we can skip a lot of extra
132
132
  // work when resolving symlinks for bundled dependencies in npm.
133
133
 
134
- var root = path.dirname((entry.root || entry).path)
134
+ var root = path.dirname((entry.root || entry).path);
135
+ if (me._global && me._global.fromBase && entry.root && entry.root.path) {
136
+ // user set 'fromBase: true' indicating tar root should be directory itself
137
+ root = entry.root.path;
138
+ }
139
+
135
140
  var wprops = {}
136
141
 
137
142
  Object.keys(entry.props || {}).forEach(function (k) {
package/lib/parse.js CHANGED
@@ -61,7 +61,7 @@ function Parse () {
61
61
  // emitting "end"
62
62
  Parse.prototype._streamEnd = function () {
63
63
  var me = this
64
- if (!me._ended) me.error("unexpected eof")
64
+ if (!me._ended || me._entry) me.error("unexpected eof")
65
65
  me.emit("end")
66
66
  }
67
67
 
@@ -102,7 +102,11 @@ Parse.prototype._process = function (c) {
102
102
 
103
103
  if (this._entry) {
104
104
  var entry = this._entry
105
- entry.write(c)
105
+ if(!entry._abort) entry.write(c)
106
+ else {
107
+ entry._remaining -= c.length
108
+ if(entry._remaining < 0) entry._remaining = 0
109
+ }
106
110
  if (entry._remaining === 0) {
107
111
  entry.end()
108
112
  this._entry = null
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
3
3
  "name": "tar",
4
4
  "description": "tar for node",
5
- "version": "2.0.1",
5
+ "version": "2.2.1",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git://github.com/isaacs/node-tar.git"
@@ -17,10 +17,10 @@
17
17
  "inherits": "2"
18
18
  },
19
19
  "devDependencies": {
20
- "graceful-fs": "^3.0.2",
20
+ "graceful-fs": "^4.1.2",
21
21
  "rimraf": "1.x",
22
22
  "tap": "0.x",
23
23
  "mkdirp": "^0.5.0"
24
24
  },
25
- "license": "BSD"
25
+ "license": "ISC"
26
26
  }
Binary file
@@ -0,0 +1,33 @@
1
+ var fs = require('fs')
2
+ var path = require('path')
3
+ var zlib = require('zlib')
4
+
5
+ var tap = require('tap')
6
+
7
+ var tar = require('../tar.js')
8
+
9
+ var file = path.join(__dirname, 'cb-never-called-1.0.1.tgz')
10
+ var target = path.join(__dirname, 'tmp/extract-test')
11
+
12
+ tap.test('preclean', function (t) {
13
+ require('rimraf').sync(__dirname + '/tmp/extract-test')
14
+ t.pass('cleaned!')
15
+ t.end()
16
+ })
17
+
18
+ tap.test('extract test', function (t) {
19
+ var extract = tar.Extract(target)
20
+ var inp = fs.createReadStream(file)
21
+
22
+ inp.pipe(zlib.createGunzip()).pipe(extract)
23
+
24
+ extract.on('error', function (er) {
25
+ t.equal(er.message, 'unexpected eof', 'error noticed')
26
+ t.end()
27
+ })
28
+
29
+ extract.on('end', function () {
30
+ t.fail('shouldn\'t reach this point due to errors')
31
+ t.end()
32
+ })
33
+ })
package/test/pack.js CHANGED
@@ -830,6 +830,10 @@ tap.test("without global header", { timeout: 10000 }, function (t) {
830
830
  runTest(t, false)
831
831
  })
832
832
 
833
+ tap.test("with from base", { timeout: 10000 }, function (t) {
834
+ runTest(t, true, true)
835
+ })
836
+
833
837
  function alphasort (a, b) {
834
838
  return a === b ? 0
835
839
  : a.toLowerCase() > b.toLowerCase() ? 1
@@ -839,7 +843,7 @@ function alphasort (a, b) {
839
843
  }
840
844
 
841
845
 
842
- function runTest (t, doGH) {
846
+ function runTest (t, doGH, doFromBase) {
843
847
  var reader = Reader({ path: input
844
848
  , filter: function () {
845
849
  return !this.path.match(/\.(tar|hex)$/)
@@ -847,7 +851,10 @@ function runTest (t, doGH) {
847
851
  , sort: alphasort
848
852
  })
849
853
 
850
- var pack = Pack(doGH ? pkg : null)
854
+ var props = doGH ? pkg : {}
855
+ if(doFromBase) props.fromBase = true;
856
+
857
+ var pack = Pack(props)
851
858
  var writer = Writer(target)
852
859
 
853
860
  // skip the global header if we're not doing that.
@@ -901,6 +908,17 @@ function runTest (t, doGH) {
901
908
  }
902
909
  t.equal(ev, wanted[0], "event type should be "+wanted[0])
903
910
 
911
+ if(doFromBase) {
912
+ if(wanted[1].path.indexOf('fixtures/') && wanted[1].path.length == 100)
913
+ wanted[1].path = wanted[1].path.replace('fixtures/', '') + 'ccccccccc'
914
+
915
+ if(wanted[1]) wanted[1].path = wanted[1].path.replace('fixtures/', '').replace('//', '/')
916
+ if(wanted[1].path == '') wanted[1].path = '/'
917
+ if(wanted[2] && wanted[2].path) wanted[2].path = wanted[2].path.replace('fixtures', '').replace(/^\//, '')
918
+
919
+ wanted[1].linkpath = wanted[1].linkpath.replace('fixtures/', '')
920
+ }
921
+
904
922
  if (ev !== wanted[0] || e.path !== wanted[1].path) {
905
923
  console.error("wanted", wanted)
906
924
  console.error([ev, e.props])
@@ -0,0 +1,29 @@
1
+ var tap = require("tap")
2
+ , tar = require("../tar.js")
3
+ , fs = require("fs")
4
+ , path = require("path")
5
+ , file = path.resolve(__dirname, "fixtures/c.tar")
6
+
7
+ tap.test("parser test", function (t) {
8
+ var parser = tar.Parse()
9
+ var total = 0
10
+ var dataTotal = 0
11
+
12
+ parser.on("end", function () {
13
+
14
+ t.equals(total-513,dataTotal,'should have discarded only c.txt')
15
+
16
+ t.end()
17
+ })
18
+
19
+ fs.createReadStream(file)
20
+ .pipe(parser)
21
+ .on('entry',function(entry){
22
+ if(entry.path === 'c.txt') entry.abort()
23
+
24
+ total += entry.size;
25
+ entry.on('data',function(data){
26
+ dataTotal += data.length
27
+ })
28
+ })
29
+ })
package/LICENCE DELETED
@@ -1,25 +0,0 @@
1
- Copyright (c) Isaac Z. Schlueter
2
- All rights reserved.
3
-
4
- The BSD License
5
-
6
- Redistribution and use in source and binary forms, with or without
7
- modification, are permitted provided that the following conditions
8
- are met:
9
- 1. Redistributions of source code must retain the above copyright
10
- notice, this list of conditions and the following disclaimer.
11
- 2. Redistributions in binary form must reproduce the above copyright
12
- notice, this list of conditions and the following disclaimer in the
13
- documentation and/or other materials provided with the distribution.
14
-
15
- THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
- POSSIBILITY OF SUCH DAMAGE.