Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2424a5a

Browse files
committedMar 2, 2018
send the options for file and pin operations that hit 'send-files-stream' under the 'qs' key. Allows any options passed to ipfs.file|pin.add-ish to be turned into qs params instead of adding all of them individually
1 parent f4312ac commit 2424a5a

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed
 

‎src/files/add-pull-stream.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
const SendFilesStream = require('../utils/send-files-stream')
44
const toPull = require('stream-to-pull-stream')
55

6-
module.exports = (send) => (options) => toPull(SendFilesStream(send, 'add')(options))
6+
module.exports = (send) => (options) =>
7+
toPull(SendFilesStream(send, 'add')({ qs: options }))

‎src/files/add.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = (send) => {
3333

3434
const files = [].concat(_files)
3535

36-
const stream = createAddStream(options)
36+
const stream = createAddStream({ qs: options })
3737
const concat = ConcatStream((result) => callback(null, result))
3838
stream.once('error', callback)
3939
stream.pipe(concat)

‎src/files/write.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = (send) => {
3131
qs: opts
3232
}
3333

34-
const stream = sendFilesStream(options)
34+
const stream = sendFilesStream({ qs: options })
3535
const concat = concatStream((result) => callback(null, result))
3636
stream.once('error', callback)
3737
stream.pipe(concat)

‎test/files.spec.js

+36
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,42 @@ describe('.files (the MFS API part)', function () {
127127
})
128128
})
129129

130+
it('files.add pins by default', (done) => {
131+
const newContent = Buffer.from(String(Math.random()))
132+
133+
ipfs.pin.ls((err, pins) => {
134+
expect(err).to.not.exist()
135+
const initialPinCount = pins.length
136+
ipfs.files.add(newContent, (err, res) => {
137+
expect(err).to.not.exist()
138+
139+
ipfs.pin.ls((err, pins) => {
140+
expect(err).to.not.exist()
141+
expect(pins.length).to.eql(initialPinCount + 1)
142+
done()
143+
})
144+
})
145+
})
146+
})
147+
148+
it('files.add with pin=false', (done) => {
149+
const newContent = Buffer.from(String(Math.random()))
150+
151+
ipfs.pin.ls((err, pins) => {
152+
expect(err).to.not.exist()
153+
const initialPinCount = pins.length
154+
ipfs.files.add(newContent, { pin: false }, (err, res) => {
155+
expect(err).to.not.exist()
156+
157+
ipfs.pin.ls((err, pins) => {
158+
expect(err).to.not.exist()
159+
expect(pins.length).to.eql(initialPinCount)
160+
done()
161+
})
162+
})
163+
})
164+
})
165+
130166
HASH_ALGS.forEach((name) => {
131167
it(`files.add with hash=${name} and raw-leaves=false`, (done) => {
132168
const content = String(Math.random() + Date.now())

‎test/util.spec.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('.util', () => {
101101
const filepath = path.join(os.tmpdir(), `${content}.txt`)
102102
fs.writeFileSync(filepath, content)
103103

104-
return ipfs.util.addFromFs(filepath, { 'only-hash': true })
104+
return ipfs.util.addFromFs(filepath, { onlyHash: true })
105105
.then(out => {
106106
fs.unlinkSync(filepath)
107107
return expectTimeout(ipfs.object.get(out[0].hash), 4000)
@@ -120,15 +120,19 @@ describe('.util', () => {
120120
})
121121
})
122122

123-
it('https', (done) => {
123+
it('https', function (done) {
124+
this.timeout(20 * 1000)
125+
124126
ipfs.util.addFromURL('https://example.com/', (err, result) => {
125127
expect(err).to.not.exist()
126128
expect(result.length).to.equal(1)
127129
done()
128130
})
129131
})
130132

131-
it('http with redirection', (done) => {
133+
it('http with redirection', function (done) {
134+
this.timeout(20 * 1000)
135+
132136
ipfs.util.addFromURL('http://covers.openlibrary.org/book/id/969165.jpg', (err, result) => {
133137
expect(err).to.not.exist()
134138
expect(result[0].hash).to.equal('QmaL9zy7YUfvWmtD5ZXp42buP7P4xmZJWFkm78p8FJqgjg')

0 commit comments

Comments
 (0)
This repository has been archived.