Skip to content

Commit cc0b415

Browse files
committed
test that 'portable' extends to gzip header
1 parent d061ff0 commit cc0b415

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/pack.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ const Pack = warner(class Pack extends MiniPass {
7575
if (typeof opt.onwarn === 'function')
7676
this.on('warn', opt.onwarn)
7777

78+
this.portable = !!opt.portable
7879
this.zip = null
7980
if (opt.gzip) {
8081
if (typeof opt.gzip !== 'object')
8182
opt.gzip = {}
83+
if (this.portable)
84+
opt.gzip.portable = true
8285
this.zip = new zlib.Gzip(opt.gzip)
8386
this.zip.on('data', chunk => super.write(chunk))
8487
this.zip.on('end', _ => super.end())
@@ -87,7 +90,6 @@ const Pack = warner(class Pack extends MiniPass {
8790
} else
8891
this.on('drain', this[ONDRAIN])
8992

90-
this.portable = !!opt.portable
9193
this.noDirRecurse = !!opt.noDirRecurse
9294
this.follow = !!opt.follow
9395
this.noMtime = !!opt.noMtime

test/pack.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,17 @@ t.test('pack a file with a prefix', t => {
125125
})
126126
})
127127

128-
t.test('pack a dir', t => {
128+
t.test('portable pack a dir', t => {
129129
const out = []
130130

131-
new Pack({ cwd: files, portable: true })
131+
new Pack({ cwd: files, portable: true, gzip: true })
132132
.add('dir')
133133
.on('data', c => out.push(c))
134134
.end()
135135
.on('end', _ => {
136-
const data = Buffer.concat(out)
136+
const zipped = Buffer.concat(out)
137+
t.equal(zipped[9], 255, 'gzip OS flag set to "unknown"')
138+
const data = new miniz.Gunzip().end(zipped).read()
137139
// dir/, dir/x, and the nulls
138140
// neither the dir or the file have any body bits
139141
const h = new Header(data)
@@ -159,8 +161,12 @@ t.test('pack a dir', t => {
159161
t.equal(data.length, 2048)
160162
t.match(data.slice(1024).toString(), /^\0{1024}$/)
161163

162-
const sync = new PackSync({ cwd: files, portable: true })
164+
const syncgz = new PackSync({ cwd: files, portable: true, gzip: true })
163165
.add('dir').end().read()
166+
167+
t.equal(syncgz[9], 255, 'gzip OS flag set to "unknown"')
168+
const sync = new miniz.Gunzip().end(zipped).read()
169+
164170
t.equal(sync.slice(512).toString(), data.slice(512).toString())
165171
const hs = new Header(sync)
166172
t.match(hs, expect)

0 commit comments

Comments
 (0)