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

feat: non-bufferring multipart body encoder #3151

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3e7baf7
feat: bufferring free multipart body encoder
Gozala Jul 7, 2020
9686628
fix: add support for String instances
Gozala Jul 8, 2020
1596609
fix: browser module paths overrides
Gozala Jul 8, 2020
e402018
fix: multipartRequest so body does not emit blobs
Gozala Jul 8, 2020
58b8d2c
Merge branch 'master' into blobity-blob
Gozala Jul 8, 2020
c1c05d0
fix: encode filename once
Gozala Jul 8, 2020
567b738
fix: add \r\n after each part of form-data
Gozala Jul 8, 2020
c9fc232
chore: write blob tests
Gozala Jul 9, 2020
39464aa
fix: incorrect header used for nsecs
Gozala Jul 9, 2020
908d99e
fix: use native blobs in elector renderer
Gozala Jul 9, 2020
bfe012f
fix: prefer native File over polyfill (in elector)
Gozala Jul 9, 2020
0dbd5af
fix: error in number of arguments that were passed
Gozala Jul 12, 2020
f015af9
chore: add comment to explain name normalization
Gozala Jul 13, 2020
499b4ef
fix: typos
Gozala Jul 13, 2020
ced65e2
chore: use normalise instead of normalize
Gozala Jul 14, 2020
ad9d617
fix: ensure that FileStream content is valid
Gozala Jul 14, 2020
09c86b9
fix: preserve file metadata
Gozala Jul 14, 2020
205fde7
fix: ensure Iterable<Bytes> instead of assuming
Gozala Jul 14, 2020
9af1bf1
fix: properly handle `null` input.
Gozala Jul 14, 2020
35d6eb3
chore: test that streams aren't used unnecessarily
Gozala Jul 14, 2020
3bdc52b
fix: file api compatiblity
Gozala Jul 14, 2020
ee74c82
chore: add file API tests
Gozala Jul 14, 2020
d44352a
Merge remote-tracking branch 'upstream/master' into blobity-blob
Gozala Jul 14, 2020
5d8ff81
chore: remove unnecessary browser entry
Gozala Jul 14, 2020
c43faf7
chore: factor out blob and file into separate libs
Gozala Jul 20, 2020
631ebf3
Merge remote-tracking branch 'upstream/master' into blobity-blob
Gozala Jul 20, 2020
2b92e4c
fix: update test to account for lastModified field
Gozala Jul 20, 2020
6421e24
chore: disable test requiring mtime support in go
Gozala Jul 20, 2020
2fc990c
fix: example test to account lastModified field
Gozala Jul 20, 2020
1859549
chore: revert changes to handle File's lastModifed
Gozala Jul 20, 2020
dcedb66
fix: reflect removed lastModified->mtime in tests
Gozala Jul 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/ipfs-core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"src",
"dist"
],
"browser": {
"./src/files/blob.js": "./src/files/blob.browser.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ipfs/js-ipfs.git"
Expand All @@ -31,7 +34,8 @@
"buffer": "^5.6.0",
"cids": "^0.8.3",
"err-code": "^2.0.0",
"ipfs-utils": "^2.2.2"
"ipfs-utils": "^2.2.2",
"web-file-polyfill": "^1.0.0"
},
"devDependencies": {
"aegir": "^23.0.0",
Expand All @@ -41,4 +45,4 @@
"dirty-chai": "^2.0.1",
"it-all": "^1.0.1"
}
}
}
25 changes: 25 additions & 0 deletions packages/ipfs-core-utils/src/files/blob.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @ts-check
'use strict'
/* eslint-env browser */

exports.Blob = Blob
exports.File = File

/**
* Universal blob reading function
* @param {Blob} blob
* @returns {AsyncIterable<Uint8Array>}
*/
const readBlob = async function * (blob) {
const { body } = new Response(blob)
const reader = body.getReader()
while (true) {
const next = await reader.read()
if (next.done) {
return
} else {
yield next.value
}
}
}
exports.readBlob = readBlob
11 changes: 11 additions & 0 deletions packages/ipfs-core-utils/src/files/blob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-check
'use strict'

// Electron in renderer process has native `Blob` but it would not pick up
// browser override. Therefor we do the runtime check and pick browser verison
// if native Blob is available and node polyfill otherwise.
if (typeof Blob === 'function') {
module.exports = require('./blob.browser')
} else {
module.exports = require('./blob.node')
}
18 changes: 18 additions & 0 deletions packages/ipfs-core-utils/src/files/blob.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-check
'use strict'

const { Blob, File } = require('web-file-polyfill')

/**
* Universal blob reading function
* @param {InstanceType<typeof window.Blob>} blob
* @returns {AsyncIterable<Uint8Array>}
*/
// eslint-disable-next-line require-await
const readBlob = async function * BlobParts (blob) {
// @ts-ignore - https://github.com/microsoft/TypeScript/issues/29867
yield * blob.stream()
}
exports.readBlob = readBlob
exports.Blob = Blob
exports.File = File
Loading