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

fix: support @web-std/file in normalize input #3750

Merged
merged 5 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions packages/ipfs-core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"uint8arrays": "^2.1.6"
},
"devDependencies": {
"@web-std/file": "^1.1.0",
"aegir": "^34.0.2",
"rimraf": "^3.0.2"
}
Expand Down
8 changes: 4 additions & 4 deletions packages/ipfs-core-utils/src/files/normalise-input/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const { Blob } = globalThis

/**
* @param {any} obj
* @returns {obj is ArrayBufferView|ArrayBuffer}
Expand All @@ -12,10 +10,12 @@ function isBytes (obj) {

/**
* @param {any} obj
* @returns {obj is Blob}
* @returns {obj is globalThis.Blob}
*/
function isBlob (obj) {
return typeof Blob !== 'undefined' && obj instanceof Blob
return obj.constructor &&
vasco-santos marked this conversation as resolved.
Show resolved Hide resolved
(obj.constructor.name === 'Blob' || obj.constructor.name === 'File') &&
typeof obj.stream === 'function'
}

/**
Expand Down
11 changes: 11 additions & 0 deletions packages/ipfs-core-utils/test/files/normalise-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { expect } = require('aegir/utils/chai')
const blobToIt = require('blob-to-it')
const uint8ArrayFromString = require('uint8arrays/from-string')
const all = require('it-all')
const { File } = require('@web-std/file')
const { Blob, ReadableStream } = globalThis
const { isBrowser, isWebWorker, isElectronRenderer } = require('ipfs-utils/src/env')

Expand Down Expand Up @@ -173,6 +174,16 @@ describe('normalise-input', function () {
testInputType(BLOB, 'Blob', false)
})

describe('@web-std/file', () => {
it('normalizes File input', async () => {
const FILE = new File([BUFFER()], 'test-file.txt')

// expect(FILE).to.be.an.instanceOf(globalThis.Blob)

await testContent(FILE)
})
})

describe('Iterable<Number>', () => {
testInputType(ARRAY, 'Iterable<Number>', false)
})
Expand Down