Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 5f5b5d0

Browse files
committed
migrate require raw to readFileSync
1 parent e62a147 commit 5f5b5d0

File tree

5 files changed

+16
-35
lines changed

5 files changed

+16
-35
lines changed

.aegir.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
module.exports = {
44
webpack: {
5-
module: {
6-
postLoaders: [{
7-
test: /\.js$/,
8-
loader: 'transform?brfs',
9-
exclude: [
10-
/js-ipfs-api\/test/
11-
]
12-
}]
5+
externals: {
6+
fs: '{}',
7+
mkdirp: '{}'
138
}
149
}
1510
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
"interface-ipfs-core": "^0.1.4",
3434
"ipfsd-ctl": "^0.14.0",
3535
"pre-commit": "^1.1.2",
36-
"raw-loader": "^0.5.1",
3736
"stream-equal": "^0.1.8",
38-
"stream-http": "^2.2.0"
37+
"stream-http": "^2.2.0",
38+
"streamifier": "^0.1.1"
3939
},
4040
"scripts": {
4141
"test": "gulp test",

test/api/add.spec.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,10 @@ const path = require('path')
88
const isNode = require('detect-node')
99
const fs = require('fs')
1010

11-
let testfile
12-
let testfileBig
1311
const testfilePath = path.join(__dirname, '/../testfile.txt')
1412

15-
if (isNode) {
16-
testfile = fs.readFileSync(testfilePath)
17-
testfileBig = fs.createReadStream(path.join(__dirname, '/../15mb.random'), { bufferSize: 128 })
18-
// testfileBig = fs.createReadStream(path.join(__dirname, '/../100mb.random'), { bufferSize: 128 })
19-
} else {
20-
testfile = require('raw!../testfile.txt')
21-
// browser goes nuts with a 100mb in memory
22-
// testfileBig = require('raw!../100mb.random')
23-
}
13+
const testfile = fs.readFileSync(testfilePath)
14+
const testfileBig = fs.readFileSync(path.join(__dirname, '/../15mb.random'))
2415

2516
describe('.add', () => {
2617
it('add file', (done) => {
@@ -122,8 +113,9 @@ describe('.add', () => {
122113
})
123114

124115
it('add a nested dir as array', (done) => {
125-
if (!isNode) return done()
126-
const fs = require('fs')
116+
if (!isNode) {
117+
return done()
118+
}
127119
const base = path.join(__dirname, '../test-folder')
128120
const content = (name) => ({
129121
path: `test-folder/${name}`,

test/api/cat.spec.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55
const expect = require('chai').expect
66
const isNode = require('detect-node')
77
const fs = require('fs')
8+
const streamifier = require('streamifier')
89

910
const path = require('path')
1011
const streamEqual = require('stream-equal')
1112

1213
let testfile
1314
let testfileBig
1415

15-
if (isNode) {
16-
testfile = fs.readFileSync(path.join(__dirname, '/../testfile.txt'))
17-
testfileBig = fs.createReadStream(path.join(__dirname, '/../15mb.random'), { bufferSize: 128 })
18-
} else {
19-
testfile = require('raw!../testfile.txt')
20-
}
16+
testfile = fs.readFileSync(path.join(__dirname, '/../testfile.txt'))
17+
testfileBig = fs.readFileSync(path.join(__dirname, '/../15mb.random'))
2118

2219
describe('.cat', () => {
2320
it('cat', (done) => {
@@ -49,7 +46,8 @@ describe('.cat', () => {
4946
expect(err).to.not.exist
5047

5148
// Do not blow out the memory of nodejs :)
52-
streamEqual(res, testfileBig, (err, equal) => {
49+
const bigStream = streamifier.createReadStream(testfileBig)
50+
streamEqual(res, bigStream, (err, equal) => {
5351
expect(err).to.not.exist
5452
expect(equal).to.be.true
5553
done()

test/api/files.spec.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ const path = require('path')
88

99
let testfile
1010

11-
if (isNode) {
12-
testfile = require('fs').readFileSync(path.join(__dirname, '/../testfile.txt'))
13-
} else {
14-
testfile = require('raw!../testfile.txt')
15-
}
11+
testfile = require('fs').readFileSync(path.join(__dirname, '/../testfile.txt'))
1612

1713
describe('.files', () => {
1814
it('files.mkdir', (done) => {

0 commit comments

Comments
 (0)