From 290c61689c83ab58303e5bf1098534295a1193b8 Mon Sep 17 00:00:00 2001 From: Page- Date: Wed, 5 Jul 2023 16:38:39 +0100 Subject: [PATCH] Allow passing empty bodies for "void" headers (#159) --- pack.js | 5 ++++- test/pack.js | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pack.js b/pack.js index 6bbb369..ed64816 100644 --- a/pack.js +++ b/pack.js @@ -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 diff --git a/test/pack.js b/test/pack.js index 0527c00..13f9a90 100644 --- a/test/pack.js +++ b/test/pack.js @@ -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)