Files: 72559d01b2c758ea8f14e5d23a18138cee44a010 / lib / index-pack.js
883 bytesRaw
1 | var pull = require('pull-stream') |
2 | var toPull = require('stream-to-pull-stream') |
3 | var cp = require('child_process') |
4 | var fs = require('fs') |
5 | var path = require('path') |
6 | var os = require('os') |
7 | |
8 | module.exports = function (packFile, cb) { |
9 | var name = Math.random().toString(36).substr(2) |
10 | var indexFilename = path.join(os.tmpdir(), name + '.idx') |
11 | var packFilename = path.join(os.tmpdir(), name + '.pack') |
12 | |
13 | var args = ['index-pack', '--stdin', '-o', indexFilename, packFilename] |
14 | var child = cp.spawn('git', args, { |
15 | stdio: ['pipe', 'pipe', 'inherit'] |
16 | }) |
17 | pull(packFile, toPull.sink(child.stdin)) |
18 | child.on('close', function (err) { |
19 | if (err) return cb(err) |
20 | fs.unlink(packFilename, function (err) { |
21 | if (err) return cb(err) |
22 | cb(null, toPull(fs.createReadStream(indexFilename), function (err) { |
23 | if (err) return console.error(err) |
24 | })) |
25 | }) |
26 | }) |
27 | } |
28 |
Built with git-ssb-web