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

Commit 6fd7776

Browse files
authored
fix: support @web-std/file in normalize input (#3750)
* fix: support @web-std/file in normalize input * chore: validate blob/file have a stream property * chore: fallback to web-std blob * fix: tests * chore: use latest file version
1 parent 58fb802 commit 6fd7776

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

packages/ipfs-core-utils/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"uint8arrays": "^2.1.6"
6060
},
6161
"devDependencies": {
62+
"@web-std/file": "^1.1.2",
6263
"aegir": "^34.0.2",
6364
"rimraf": "^3.0.2"
6465
}

packages/ipfs-core-utils/src/files/normalise-input/utils.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
const { Blob } = globalThis
4-
53
/**
64
* @param {any} obj
75
* @returns {obj is ArrayBufferView|ArrayBuffer}
@@ -12,10 +10,12 @@ function isBytes (obj) {
1210

1311
/**
1412
* @param {any} obj
15-
* @returns {obj is Blob}
13+
* @returns {obj is globalThis.Blob}
1614
*/
1715
function isBlob (obj) {
18-
return typeof Blob !== 'undefined' && obj instanceof Blob
16+
return obj.constructor &&
17+
(obj.constructor.name === 'Blob' || obj.constructor.name === 'File') &&
18+
typeof obj.stream === 'function'
1919
}
2020

2121
/**

packages/ipfs-core-utils/test/files/normalise-input.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { expect } = require('aegir/utils/chai')
66
const blobToIt = require('blob-to-it')
77
const uint8ArrayFromString = require('uint8arrays/from-string')
88
const all = require('it-all')
9+
const { File } = require('@web-std/file')
910
const { Blob, ReadableStream } = globalThis
1011
const { isBrowser, isWebWorker, isElectronRenderer } = require('ipfs-utils/src/env')
1112

@@ -173,6 +174,14 @@ describe('normalise-input', function () {
173174
testInputType(BLOB, 'Blob', false)
174175
})
175176

177+
describe('@web-std/file', () => {
178+
it('normalizes File input', async () => {
179+
const FILE = new File([BUFFER()], 'test-file.txt')
180+
181+
await testContent(FILE)
182+
})
183+
})
184+
176185
describe('Iterable<Number>', () => {
177186
testInputType(ARRAY, 'Iterable<Number>', false)
178187
})

0 commit comments

Comments
 (0)