be standard
This commit is contained in:
parent
af1abde6a4
commit
33a55ac474
5 changed files with 208 additions and 212 deletions
|
@ -86,7 +86,7 @@ var indexOf = function(block, num, offset, end) {
|
|||
var cksum = function (block) {
|
||||
var sum = 8 * 32
|
||||
for (var i = 0; i < 148; i++) sum += block[i]
|
||||
for (var i = 156; i < 512; i++) sum += block[i]
|
||||
for (var j = 156; j < 512; j++) sum += block[j]
|
||||
return sum
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ var decodeOct = function(val, offset) {
|
|||
}
|
||||
|
||||
var decodeStr = function (val, offset, length) {
|
||||
return val.slice(offset, indexOf(val, 0, offset, offset+length)).toString();
|
||||
return val.slice(offset, indexOf(val, 0, offset, offset + length)).toString()
|
||||
}
|
||||
|
||||
var addLength = function (str) {
|
||||
|
@ -133,8 +133,7 @@ exports.decodePax = function(buf) {
|
|||
while (buf.length) {
|
||||
var i = 0
|
||||
while (i < buf.length && buf[i] !== 32) i++
|
||||
|
||||
var len = parseInt(buf.slice(0, i).toString())
|
||||
var len = parseInt(buf.slice(0, i).toString(), 10)
|
||||
if (!len) return result
|
||||
|
||||
var b = buf.slice(i + 1, len - 1).toString()
|
||||
|
@ -217,7 +216,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)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?')
|
||||
|
||||
return {
|
||||
name: name,
|
||||
|
|
1
pack.js
1
pack.js
|
@ -3,7 +3,6 @@ var eos = require('end-of-stream')
|
|||
var util = require('util')
|
||||
|
||||
var Readable = require('readable-stream').Readable
|
||||
var PassThrough = require('readable-stream').PassThrough
|
||||
var Writable = require('readable-stream').Writable
|
||||
var StringDecoder = require('string_decoder').StringDecoder
|
||||
|
||||
|
|
|
@ -14,10 +14,11 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"concat-stream": "^1.4.6",
|
||||
"standard": "^5.3.1",
|
||||
"tape": "^3.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test/*.js"
|
||||
"test": "standard && tape test/*.js"
|
||||
},
|
||||
"keywords": [
|
||||
"tar",
|
||||
|
|
|
@ -23,7 +23,7 @@ test('one-file', function(t) {
|
|||
extract.on('entry', function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'test.txt',
|
||||
mode: 0644,
|
||||
mode: parseInt('644', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 12,
|
||||
|
@ -59,7 +59,7 @@ test('chunked-one-file', function(t) {
|
|||
extract.on('entry', function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'test.txt',
|
||||
mode: 0644,
|
||||
mode: parseInt('644', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 12,
|
||||
|
@ -91,7 +91,6 @@ test('chunked-one-file', function(t) {
|
|||
extract.end()
|
||||
})
|
||||
|
||||
|
||||
test('multi-file', function (t) {
|
||||
t.plan(5)
|
||||
|
||||
|
@ -101,7 +100,7 @@ test('multi-file', function(t) {
|
|||
var onfile1 = function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'file-1.txt',
|
||||
mode: 0644,
|
||||
mode: parseInt('644', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 12,
|
||||
|
@ -124,7 +123,7 @@ test('multi-file', function(t) {
|
|||
var onfile2 = function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'file-2.txt',
|
||||
mode: 0644,
|
||||
mode: parseInt('644', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 12,
|
||||
|
@ -162,7 +161,7 @@ test('chunked-multi-file', function(t) {
|
|||
var onfile1 = function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'file-1.txt',
|
||||
mode: 0644,
|
||||
mode: parseInt('644', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 12,
|
||||
|
@ -185,7 +184,7 @@ test('chunked-multi-file', function(t) {
|
|||
var onfile2 = function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'file-2.txt',
|
||||
mode: 0644,
|
||||
mode: parseInt('644', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 12,
|
||||
|
@ -227,7 +226,7 @@ test('types', function(t) {
|
|||
var ondir = function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'directory',
|
||||
mode: 0755,
|
||||
mode: parseInt('755', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 0,
|
||||
|
@ -249,7 +248,7 @@ test('types', function(t) {
|
|||
var onlink = function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'directory-link',
|
||||
mode: 0755,
|
||||
mode: parseInt('755', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 0,
|
||||
|
@ -286,7 +285,7 @@ test('long-name', function(t) {
|
|||
extract.on('entry', function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'my/file/is/longer/than/100/characters/and/should/use/the/prefix/header/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/filename.txt',
|
||||
mode: 0644,
|
||||
mode: parseInt('644', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 16,
|
||||
|
@ -322,7 +321,7 @@ test('unicode-bsd', function(t) { // can unpack a bsdtar unicoded tarball
|
|||
extract.on('entry', function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'høllø.txt',
|
||||
mode: 0644,
|
||||
mode: parseInt('644', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 4,
|
||||
|
@ -358,7 +357,7 @@ test('unicode', function(t) { // can unpack a bsdtar unicoded tarball
|
|||
extract.on('entry', function (header, stream, callback) {
|
||||
t.deepEqual(header, {
|
||||
name: 'høstål.txt',
|
||||
mode: 0644,
|
||||
mode: parseInt('644', 8),
|
||||
uid: 501,
|
||||
gid: 20,
|
||||
size: 8,
|
||||
|
@ -451,5 +450,4 @@ test('gnu long path', function(t) {
|
|||
})
|
||||
|
||||
extract.end(fs.readFileSync(fixtures.GNU_LONG_PATH))
|
||||
|
||||
})
|
15
test/pack.js
15
test/pack.js
|
@ -12,7 +12,7 @@ test('one-file', function(t) {
|
|||
pack.entry({
|
||||
name: 'test.txt',
|
||||
mtime: new Date(1387580181000),
|
||||
mode:0644,
|
||||
mode: parseInt('644', 8),
|
||||
uname: 'maf',
|
||||
gname: 'staff',
|
||||
uid: 501,
|
||||
|
@ -35,7 +35,7 @@ test('multi-file', function(t) {
|
|||
pack.entry({
|
||||
name: 'file-1.txt',
|
||||
mtime: new Date(1387580181000),
|
||||
mode:0644,
|
||||
mode: parseInt('644', 8),
|
||||
uname: 'maf',
|
||||
gname: 'staff',
|
||||
uid: 501,
|
||||
|
@ -45,7 +45,7 @@ test('multi-file', function(t) {
|
|||
pack.entry({
|
||||
name: 'file-2.txt',
|
||||
mtime: new Date(1387580181000),
|
||||
mode:0644,
|
||||
mode: parseInt('644', 8),
|
||||
size: 12,
|
||||
uname: 'maf',
|
||||
gname: 'staff',
|
||||
|
@ -69,7 +69,7 @@ test('types', function(t) {
|
|||
name: 'directory',
|
||||
mtime: new Date(1387580181000),
|
||||
type: 'directory',
|
||||
mode:0755,
|
||||
mode: parseInt('755', 8),
|
||||
uname: 'maf',
|
||||
gname: 'staff',
|
||||
uid: 501,
|
||||
|
@ -81,7 +81,7 @@ test('types', function(t) {
|
|||
mtime: new Date(1387580181000),
|
||||
type: 'symlink',
|
||||
linkname: 'directory',
|
||||
mode:0755,
|
||||
mode: parseInt('755', 8),
|
||||
uname: 'maf',
|
||||
gname: 'staff',
|
||||
uid: 501,
|
||||
|
@ -94,7 +94,6 @@ test('types', function(t) {
|
|||
t.equal(data.length & 511, 0)
|
||||
t.deepEqual(data, fs.readFileSync(fixtures.TYPES_TAR))
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
test('long-name', function (t) {
|
||||
|
@ -105,7 +104,7 @@ test('long-name', function(t) {
|
|||
name: 'my/file/is/longer/than/100/characters/and/should/use/the/prefix/header/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/filename.txt',
|
||||
mtime: new Date(1387580181000),
|
||||
type: 'file',
|
||||
mode:0644,
|
||||
mode: parseInt('644', 8),
|
||||
uname: 'maf',
|
||||
gname: 'staff',
|
||||
uid: 501,
|
||||
|
@ -128,7 +127,7 @@ test('unicode', function(t) {
|
|||
name: 'høstål.txt',
|
||||
mtime: new Date(1387580181000),
|
||||
type: 'file',
|
||||
mode:0644,
|
||||
mode: parseInt('644', 8),
|
||||
uname: 'maf',
|
||||
gname: 'staff',
|
||||
uid: 501,
|
||||
|
|
Loading…
Reference in a new issue