Files: 19f56371ca30ab1b788a7f999d532d523f890469 / lib / index-pack.js
1194 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 child = cp.spawn('git', ['index-pack', '--stdin', '--fix-thin', |
14 | '-o', indexFilename, packFilename], { |
15 | stdio: ['pipe', 'pipe', 'inherit'] |
16 | }) |
17 | pull(packFile, toPull.sink(child.stdin)) |
18 | child.on('close', function (err) { |
19 | if (err) return cb(new Error('git index-pack returned ' + err)) |
20 | cb(null, |
21 | toPull(fs.createReadStream(indexFilename), function (err) { |
22 | fs.unlink(indexFilename, function (err) { |
23 | if (err) return console.error(err) |
24 | }) |
25 | }), |
26 | // the output packfile here is the original packfile transformed to make |
27 | // it not thin. |
28 | toPull(fs.createReadStream(packFilename), function (err) { |
29 | fs.unlink(packFilename, function (err) { |
30 | if (err) return console.error(err) |
31 | }) |
32 | }) |
33 | ) |
34 | }) |
35 | } |
36 |
Built with git-ssb-web