This repository was archived by the owner on Aug 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathimport-export.js
72 lines (61 loc) · 1.81 KB
/
import-export.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 5] */
'use strict'
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const BlockService = require('ipfs-block-service')
const Ipld = require('ipld')
const pull = require('pull-stream')
const loadFixture = require('aegir/fixtures')
const bigFile = loadFixture('test/fixtures/1.2MiB.txt')
const unixFSEngine = require('./../')
const exporter = unixFSEngine.exporter
const strategies = [
'flat',
'balanced',
'trickle'
]
function fileEql (f1, fileData, callback) {
pull(
f1.content,
pull.concat((err, data) => {
expect(err).to.not.exist()
// TODO: eql is super slow at comparing large buffers
// expect(data).to.eql(fileData)
callback()
})
)
}
module.exports = (repo) => {
describe('import and export', function () {
this.timeout(30 * 1000)
strategies.forEach((strategy) => {
const importerOptions = { strategy: strategy }
describe('using builder: ' + strategy, () => {
let ipld
before(() => {
const bs = new BlockService(repo)
ipld = new Ipld({blockService: bs})
})
it('import and export', (done) => {
const path = strategy + '-big.dat'
pull(
pull.values([{ path: path, content: pull.values(bigFile) }]),
unixFSEngine.importer(ipld, importerOptions),
pull.map((file) => {
expect(file.path).to.eql(path)
return exporter(file.multihash, ipld)
}),
pull.flatten(),
pull.collect((err, files) => {
expect(err).to.not.exist()
expect(files[0].size).to.eql(bigFile.length)
fileEql(files[0], bigFile, done)
})
)
})
})
})
})
}