git ssb

0+

cel / pull-git-remote-helper



Tree: 72559d01b2c758ea8f14e5d23a18138cee44a010

Files: 72559d01b2c758ea8f14e5d23a18138cee44a010 / lib / index-pack.js

883 bytesRaw
1var pull = require('pull-stream')
2var toPull = require('stream-to-pull-stream')
3var cp = require('child_process')
4var fs = require('fs')
5var path = require('path')
6var os = require('os')
7
8module.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