be standard

This commit is contained in:
Mathias Buus 2015-11-06 15:30:21 -08:00
parent af1abde6a4
commit 33a55ac474
5 changed files with 208 additions and 212 deletions

View file

@ -86,7 +86,7 @@ var indexOf = function(block, num, offset, end) {
var cksum = function (block) { var cksum = function (block) {
var sum = 8 * 32 var sum = 8 * 32
for (var i = 0; i < 148; i++) sum += block[i] 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 return sum
} }
@ -105,7 +105,7 @@ var decodeOct = function(val, offset) {
} }
var decodeStr = function (val, offset, length) { 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) { var addLength = function (str) {
@ -133,8 +133,7 @@ exports.decodePax = function(buf) {
while (buf.length) { while (buf.length) {
var i = 0 var i = 0
while (i < buf.length && buf[i] !== 32) i++ while (i < buf.length && buf[i] !== 32) i++
var len = parseInt(buf.slice(0, i).toString(), 10)
var len = parseInt(buf.slice(0, i).toString())
if (!len) return result if (!len) return result
var b = buf.slice(i + 1, len - 1).toString() var b = buf.slice(i + 1, len - 1).toString()
@ -217,7 +216,7 @@ exports.decode = function(buf) {
if (c === 8 * 32) return null if (c === 8 * 32) return null
// valid checksum // 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 { return {
name: name, name: name,

View file

@ -3,7 +3,6 @@ var eos = require('end-of-stream')
var util = require('util') var util = require('util')
var Readable = require('readable-stream').Readable var Readable = require('readable-stream').Readable
var PassThrough = require('readable-stream').PassThrough
var Writable = require('readable-stream').Writable var Writable = require('readable-stream').Writable
var StringDecoder = require('string_decoder').StringDecoder var StringDecoder = require('string_decoder').StringDecoder

View file

@ -14,10 +14,11 @@
}, },
"devDependencies": { "devDependencies": {
"concat-stream": "^1.4.6", "concat-stream": "^1.4.6",
"standard": "^5.3.1",
"tape": "^3.0.3" "tape": "^3.0.3"
}, },
"scripts": { "scripts": {
"test": "tape test/*.js" "test": "standard && tape test/*.js"
}, },
"keywords": [ "keywords": [
"tar", "tar",

View file

@ -23,7 +23,7 @@ test('one-file', function(t) {
extract.on('entry', function (header, stream, callback) { extract.on('entry', function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'test.txt', name: 'test.txt',
mode: 0644, mode: parseInt('644', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 12, size: 12,
@ -59,7 +59,7 @@ test('chunked-one-file', function(t) {
extract.on('entry', function (header, stream, callback) { extract.on('entry', function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'test.txt', name: 'test.txt',
mode: 0644, mode: parseInt('644', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 12, size: 12,
@ -91,7 +91,6 @@ test('chunked-one-file', function(t) {
extract.end() extract.end()
}) })
test('multi-file', function (t) { test('multi-file', function (t) {
t.plan(5) t.plan(5)
@ -101,7 +100,7 @@ test('multi-file', function(t) {
var onfile1 = function (header, stream, callback) { var onfile1 = function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'file-1.txt', name: 'file-1.txt',
mode: 0644, mode: parseInt('644', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 12, size: 12,
@ -124,7 +123,7 @@ test('multi-file', function(t) {
var onfile2 = function (header, stream, callback) { var onfile2 = function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'file-2.txt', name: 'file-2.txt',
mode: 0644, mode: parseInt('644', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 12, size: 12,
@ -162,7 +161,7 @@ test('chunked-multi-file', function(t) {
var onfile1 = function (header, stream, callback) { var onfile1 = function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'file-1.txt', name: 'file-1.txt',
mode: 0644, mode: parseInt('644', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 12, size: 12,
@ -185,7 +184,7 @@ test('chunked-multi-file', function(t) {
var onfile2 = function (header, stream, callback) { var onfile2 = function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'file-2.txt', name: 'file-2.txt',
mode: 0644, mode: parseInt('644', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 12, size: 12,
@ -227,7 +226,7 @@ test('types', function(t) {
var ondir = function (header, stream, callback) { var ondir = function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'directory', name: 'directory',
mode: 0755, mode: parseInt('755', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 0, size: 0,
@ -249,7 +248,7 @@ test('types', function(t) {
var onlink = function (header, stream, callback) { var onlink = function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'directory-link', name: 'directory-link',
mode: 0755, mode: parseInt('755', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 0, size: 0,
@ -286,7 +285,7 @@ test('long-name', function(t) {
extract.on('entry', function (header, stream, callback) { extract.on('entry', function (header, stream, callback) {
t.deepEqual(header, { 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', 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, uid: 501,
gid: 20, gid: 20,
size: 16, size: 16,
@ -322,7 +321,7 @@ test('unicode-bsd', function(t) { // can unpack a bsdtar unicoded tarball
extract.on('entry', function (header, stream, callback) { extract.on('entry', function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'høllø.txt', name: 'høllø.txt',
mode: 0644, mode: parseInt('644', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 4, size: 4,
@ -358,7 +357,7 @@ test('unicode', function(t) { // can unpack a bsdtar unicoded tarball
extract.on('entry', function (header, stream, callback) { extract.on('entry', function (header, stream, callback) {
t.deepEqual(header, { t.deepEqual(header, {
name: 'høstål.txt', name: 'høstål.txt',
mode: 0644, mode: parseInt('644', 8),
uid: 501, uid: 501,
gid: 20, gid: 20,
size: 8, size: 8,
@ -451,5 +450,4 @@ test('gnu long path', function(t) {
}) })
extract.end(fs.readFileSync(fixtures.GNU_LONG_PATH)) extract.end(fs.readFileSync(fixtures.GNU_LONG_PATH))
}) })

View file

@ -12,7 +12,7 @@ test('one-file', function(t) {
pack.entry({ pack.entry({
name: 'test.txt', name: 'test.txt',
mtime: new Date(1387580181000), mtime: new Date(1387580181000),
mode:0644, mode: parseInt('644', 8),
uname: 'maf', uname: 'maf',
gname: 'staff', gname: 'staff',
uid: 501, uid: 501,
@ -35,7 +35,7 @@ test('multi-file', function(t) {
pack.entry({ pack.entry({
name: 'file-1.txt', name: 'file-1.txt',
mtime: new Date(1387580181000), mtime: new Date(1387580181000),
mode:0644, mode: parseInt('644', 8),
uname: 'maf', uname: 'maf',
gname: 'staff', gname: 'staff',
uid: 501, uid: 501,
@ -45,7 +45,7 @@ test('multi-file', function(t) {
pack.entry({ pack.entry({
name: 'file-2.txt', name: 'file-2.txt',
mtime: new Date(1387580181000), mtime: new Date(1387580181000),
mode:0644, mode: parseInt('644', 8),
size: 12, size: 12,
uname: 'maf', uname: 'maf',
gname: 'staff', gname: 'staff',
@ -69,7 +69,7 @@ test('types', function(t) {
name: 'directory', name: 'directory',
mtime: new Date(1387580181000), mtime: new Date(1387580181000),
type: 'directory', type: 'directory',
mode:0755, mode: parseInt('755', 8),
uname: 'maf', uname: 'maf',
gname: 'staff', gname: 'staff',
uid: 501, uid: 501,
@ -81,7 +81,7 @@ test('types', function(t) {
mtime: new Date(1387580181000), mtime: new Date(1387580181000),
type: 'symlink', type: 'symlink',
linkname: 'directory', linkname: 'directory',
mode:0755, mode: parseInt('755', 8),
uname: 'maf', uname: 'maf',
gname: 'staff', gname: 'staff',
uid: 501, uid: 501,
@ -94,7 +94,6 @@ test('types', function(t) {
t.equal(data.length & 511, 0) t.equal(data.length & 511, 0)
t.deepEqual(data, fs.readFileSync(fixtures.TYPES_TAR)) t.deepEqual(data, fs.readFileSync(fixtures.TYPES_TAR))
})) }))
}) })
test('long-name', function (t) { 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', 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), mtime: new Date(1387580181000),
type: 'file', type: 'file',
mode:0644, mode: parseInt('644', 8),
uname: 'maf', uname: 'maf',
gname: 'staff', gname: 'staff',
uid: 501, uid: 501,
@ -128,7 +127,7 @@ test('unicode', function(t) {
name: 'høstål.txt', name: 'høstål.txt',
mtime: new Date(1387580181000), mtime: new Date(1387580181000),
type: 'file', type: 'file',
mode:0644, mode: parseInt('644', 8),
uname: 'maf', uname: 'maf',
gname: 'staff', gname: 'staff',
uid: 501, uid: 501,