Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 864ab81

Browse files
committed
feat: streaming http requests
No more 4GB file limits. Still need to get http tests passing properly.
1 parent 673deb9 commit 864ab81

39 files changed

+179
-340
lines changed

packages/interface-ipfs-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"multihashes": "^0.4.14",
5353
"multihashing-async": "^0.8.0",
5454
"peer-id": "^0.13.5",
55-
"readable-stream": "^3.4.0"
55+
"readable-stream": "^3.4.0",
56+
"temp-write": "^4.0.0"
5657
},
5758
"devDependencies": {
5859
"aegir": "^21.3.0",

packages/interface-ipfs-core/src/files/stat.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const all = require('it-all')
66
const { fixtures } = require('../utils')
77
const { getDescribe, getIt, expect } = require('../utils/mocha')
88
const createShardedDirectory = require('../utils/create-sharded-directory')
9-
const mc = require('multicodec')
109
const CID = require('cids')
1110
const mh = require('multihashes')
1211
const Block = require('ipfs-block')

packages/interface-ipfs-core/src/files/write.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = (common, options) => {
6161
})
6262
}
6363

64-
describe.only('.files.write', function () {
64+
describe('.files.write', function () {
6565
this.timeout(40 * 1000)
6666

6767
let ipfs
@@ -93,19 +93,15 @@ module.exports = (common, options) => {
9393
}
9494

9595
before(async () => {
96-
console.info('spawning')
9796
ipfs = (await common.spawn()).api
98-
console.info('spawned')
9997
})
10098

10199
after(() => common.clean())
102100

103101
it('explodes if it cannot convert content to a source', async () => {
104-
console.info('writing')
105102
await expect(ipfs.files.write('/foo', -1, {
106103
create: true
107104
})).to.eventually.be.rejected()
108-
console.info('wrote')
109105
})
110106

111107
it('explodes if given an invalid path', async () => {

packages/interface-ipfs-core/src/utils/create-shard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const last = require('it-last')
55
const createShard = async (ipfs, files, shardSplitThreshold = 10) => {
66
const result = await last(ipfs.add(files, {
77
enableShardingExperiment: true,
8-
shardSplitThreshold,
8+
shardSplitThreshold
99
// reduceSingleLeafToSelf: false, // same as go-ipfs-mfs implementation, differs from `ipfs add`(!)
1010
// rawLeaves: 'raw' // same as go-ipfs-mfs implementation, differs from `ipfs add`(!)
1111
}))

packages/ipfs-http-client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"cids": "^0.7.3",
4848
"debug": "^4.1.0",
4949
"form-data": "^3.0.0",
50+
"hat": "0.0.3",
5051
"ipfs-block": "^0.8.1",
5152
"ipfs-utils": "^0.7.2",
5253
"ipld-dag-cbor": "^0.15.1",

packages/ipfs-http-client/src/add/index.js renamed to packages/ipfs-http-client/src/add.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
const CID = require('cids')
44
const merge = require('merge-options')
5-
const { toFormData } = require('./form-data')
6-
const toCamel = require('../lib/object-to-camel')
7-
const configure = require('../lib/configure')
5+
const toCamel = require('./lib/object-to-camel')
6+
const configure = require('./lib/configure')
7+
const multipartRequest = require('./lib/multipart-request')
88

99
module.exports = configure((api) => {
1010
return async function * add (input, options = {}) {
@@ -18,10 +18,13 @@ module.exports = configure((api) => {
1818
}
1919
)
2020

21+
const { body, headers } = multipartRequest(input)
22+
2123
const res = await api.ndjson('add', {
2224
method: 'POST',
2325
searchParams: options,
24-
body: await toFormData(input),
26+
headers,
27+
body: body,
2528
timeout: options.timeout,
2629
signal: options.signal
2730
})

packages/ipfs-http-client/src/add/form-data.browser.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

packages/ipfs-http-client/src/add/form-data.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

packages/ipfs-http-client/src/files/write.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
'use strict'
22

3-
const toFormData = require('../lib/buffer-to-form-data')
3+
const normaliseInput = require('ipfs-utils/src/files/normalise-input')
44
const modeToString = require('../lib/mode-to-string')
55
const mtimeToObject = require('../lib/mtime-to-object')
66
const configure = require('../lib/configure')
7+
const multipartRequest = require('../lib/multipart-request')
78

89
module.exports = configure(api => {
910
return async (path, input, options = {}) => {
10-
const mtime = mtimeToObject(options.mtime)
11-
1211
const searchParams = new URLSearchParams(options)
1312
searchParams.set('arg', path)
1413
searchParams.set('stream-channels', 'true')
1514
searchParams.set('hash', options.hashAlg)
1615
searchParams.set('hashAlg', null)
17-
if (mtime) {
18-
searchParams.set('mtime', mtime.secs)
19-
searchParams.set('mtimeNsecs', mtime.nsecs)
20-
}
16+
17+
const { body, headers } = multipartRequest(normaliseInput({
18+
content: input,
19+
path: path,
20+
mode: modeToString(options.mode),
21+
mtime: mtimeToObject(options.mtime)
22+
}))
2123

2224
const res = await api.post('files/write', {
2325
timeout: options.timeout,
2426
signal: options.signal,
2527
searchParams,
26-
body: multipartRequest([{
27-
content: input,
28-
path: path,
29-
mode: options.mode,
30-
mtime: options.mtime
31-
}], boundary)
28+
headers,
29+
body
3230
})
3331

3432
return res.text()

packages/ipfs-http-client/src/lib/multipart-request.browser.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)