Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time. Cannot retrieve contributors at this time
79 lines (68 sloc) 1.81 KB
var archiveit = require('..')
var fs = require('fs')
var crypto = require('crypto')
var pump = require('pump')
var raf = require('random-access-file')
var test = require('tape')
var from2 = require('from2-string')
var concat = require('concat-stream')
var hyperdrive = require('hyperdrive')
var path = require('path')
var memdb = require('memdb')
var tar = require('tar-stream')
test('check tar contents', function (t) {
var drive = hyperdrive(memdb())
var archive = drive.createArchive()
var ws = archive.createFileWriteStream('hello.txt')
ws.write('hello')
ws.write('world')
ws.end()
var ws = archive.createFileWriteStream('verden.txt')
ws.write('hello')
ws.write('verden')
ws.end()
archive.finalize(function () {
t.ok(archive.key.toString('hex'))
var tar = archiveit(archive)
var extract = extractor(t)
tar.pipe(extract)
})
})
function extractor (t) {
var total = 0
var extract = tar.extract()
extract.on('entry', function (header, stream, callback) {
stream.on('end', function () {
total += 1
callback()
})
if (header.type === 'file') {
if (header.name === 'hello.txt') {
stream.pipe(concat(function (data) {
t.equals('helloworld', data.toString(), 'world contents')
}))
}
}
stream.resume()
})
extract.on('finish', function () {
t.equals(total, 2, 'total is 2')
t.end()
})
return extract
}
test('use big file', function (t) {
var drive = hyperdrive(memdb())
var archive = drive.createArchive()
var ws = archive.createFileWriteStream('hello.txt')
var read = from2(crypto.randomBytes(12 * 256 * 100).toString())
pump(read, ws, function () {
archive.finalize(function () {
var tar = archiveit(archive)
tar.resume()
tar.on('end', function () {
t.end()
})
})
})
})