Skip to content

Commit

Permalink
Allow passing empty bodies for "void" headers (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Page- committed Jul 5, 2023
1 parent 93ab386 commit 290c616
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pack.js
Expand Up @@ -73,7 +73,10 @@ class Sink extends Writable {
}

if (this._isVoid) {
return cb(new Error('No body allowed for this entry'))
if (data.byteLength > 0) {
return cb(new Error('No body allowed for this entry'))
}
return cb()
}

this.written += data.byteLength
Expand Down
24 changes: 24 additions & 0 deletions test/pack.js
Expand Up @@ -124,6 +124,30 @@ test('types', function (t) {
}))
})

test('empty directory body is valid', function (t) {
t.plan(1)

const pack = tar.pack()

pack.entry({
name: 'directory',
mtime: new Date(1387580181000),
type: 'directory',
mode: 0o755,
uname: 'maf',
gname: 'staff',
uid: 501,
gid: 20
}, '')

pack.finalize()

pack.resume()

pack.on('error', () => t.fail('should not throw'))
pack.on('close', () => t.pass('closed'))
})

test('long-name', function (t) {
t.plan(2)

Expand Down

0 comments on commit 290c616

Please sign in to comment.