This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
module.exports = manifest | ||
function manifest () { | ||
// The tarball handler will take care of it! | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict' | ||
|
||
const BB = require('bluebird') | ||
|
||
const fs = require('graceful-fs') | ||
const pipe = require('mississippi').pipe | ||
const through = require('mississippi').through | ||
|
||
const readFileAsync = BB.promisify(fs.readFile) | ||
const statAsync = BB.promisify(fs.stat) | ||
|
||
const MAX_BULK_SIZE = 2 * 1024 * 1024 // 2MB | ||
|
||
module.exports = tarball | ||
function tarball (spec, opts) { | ||
const src = spec._resolved || spec.spec | ||
const stream = through() | ||
statAsync(src).then(stat => { | ||
if (stat.size <= MAX_BULK_SIZE) { | ||
// YAY LET'S DO THING IN BULK | ||
return readFileAsync(src).then(data => { | ||
stream.write(data, () => { | ||
stream.end() | ||
}) | ||
}) | ||
} else { | ||
return pipe(fs.createReadStream(src), stream) | ||
} | ||
}, err => stream.emit('error', err)) | ||
return stream | ||
} | ||
|
||
module.exports.fromManifest = fromManifest | ||
function fromManifest (manifest, spec, opts) { | ||
return tarball(manifest || spec, opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict' | ||
|
||
const BB = require('bluebird') | ||
|
||
const finished = BB.promisify(require('mississippi').finished) | ||
const fs = BB.promisifyAll(require('fs')) | ||
const mockTar = require('./util/mock-tarball') | ||
const npmlog = require('npmlog') | ||
const path = require('path') | ||
const test = require('tap').test | ||
|
||
const CACHE = require('./util/test-dir')(__filename) | ||
|
||
const tarball = require('../lib/handlers/local/tarball') | ||
|
||
npmlog.level = process.env.LOGLEVEL || 'silent' | ||
const OPTS = { | ||
log: npmlog | ||
} | ||
|
||
test('basic tarball streaming', function (t) { | ||
const pkg = { | ||
'package.json': JSON.stringify({ | ||
name: 'foo', | ||
version: '1.2.3' | ||
}), | ||
'index.js': 'console.log("hello world!")' | ||
} | ||
const tarballPath = path.join(CACHE, 'foo-1.2.3.tgz') | ||
return mockTar(pkg).then(tarData => { | ||
return fs.writeFileAsync(tarballPath, tarData).then(() => { | ||
let data = '' | ||
return finished( | ||
tarball({ | ||
type: 'local', | ||
spec: tarballPath | ||
}, OPTS).on('data', d => { data += d }) | ||
).then(() => { | ||
t.equal(data, tarData, 'fetched tarball data matches one from local') | ||
}) | ||
}) | ||
}) | ||
}) |