Skip to content

Commit

Permalink
chore: use a local instead of remote file for test
Browse files Browse the repository at this point in the history
I was able to replicate the same behavior from #332 by piping a readable
stream with a `highWaterMark` of 1 to extract. I confirmed this test
still failed without the fixes from #332 and now passes.
  • Loading branch information
lukekarrys committed Oct 27, 2022
1 parent 57493ee commit 767530e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
17 changes: 15 additions & 2 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ const DONE = Symbol('onDone')
const SAW_VALID_ENTRY = Symbol('sawValidEntry')
const SAW_NULL_BLOCK = Symbol('sawNullBlock')
const SAW_EOF = Symbol('sawEOF')
const CLOSESTREAM = Symbol('closeStream')
const CLOSESTREAMTICK = Symbol('closeStreamTick')
const CLOSESTREAMMICRO = Symbol('closeStreamMicro')
const CLOSESTREAMPROMISE = Symbol('closeStreamPromise')
const CLOSESTREAM = process.env.TAR_CLOSE === 'tick'
? CLOSESTREAMTICK
: process.env.TAR_CLOSE === 'micro' ? CLOSESTREAMMICRO
: process.env.TAR_CLOSE === 'promise' ? CLOSESTREAMPROMISE
: null

const noop = _ => true

Expand Down Expand Up @@ -222,7 +229,13 @@ module.exports = warner(class Parser extends EE {
}

[CLOSESTREAM] () {
nextTick(() => this.emit('close'))
if (CLOSESTREAM === CLOSESTREAMTICK) {
nextTick(() => this.emit('close'))
} else if (CLOSESTREAM === CLOSESTREAMMICRO) {
queueMicrotask(() => this.emit('close'))
} else if (CLOSESTREAM === CLOSESTREAMPROMISE) {
Promise.resolve().then(() => this.emit('close'))
}
}

[PROCESSENTRY] (entry) {
Expand Down
15 changes: 8 additions & 7 deletions test/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const { promisify } = require('util')
const rimraf = promisify(require('rimraf'))
const mutateFS = require('mutate-fs')
const pipeline = promisify(require('stream').pipeline)
const https = require('https')

t.teardown(_ => rimraf(extractdir))

Expand Down Expand Up @@ -57,6 +56,7 @@ t.test('basic extracting', t => {
})

t.test('ensure an open stream is not prematuraly closed', t => {
t.plan(1)
const dir = path.resolve(extractdir, 'basic-with-stream')

t.beforeEach(async () => {
Expand All @@ -65,18 +65,19 @@ t.test('ensure an open stream is not prematuraly closed', t => {
})

const check = async t => {
fs.lstatSync(dir + '/node-tar-main/LICENSE')
t.ok(fs.lstatSync(dir + '/long-path'))
await rimraf(dir)
t.end()
}

t.test('async promisey', t => {
https.get('https://codeload.github.com/npm/node-tar/tar.gz/main', (stream) => {
return pipeline(
stream,
x({ cwd: dir }, ['node-tar-main/LICENSE'])
).then(_ => check(t))
const stream = fs.createReadStream(path.resolve(tars, 'long-paths.tar'), {
highWaterMark: 1,
})
pipeline(
stream,
x({ cwd: dir })
).then(_ => check(t))
})

t.end()
Expand Down

0 comments on commit 767530e

Please sign in to comment.