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

fix: send blobs when running ipfs-http-client in the browser #3184

Merged
merged 15 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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
298 changes: 0 additions & 298 deletions packages/ipfs-core-utils/src/files/normalise-input.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict'

const normaliseContent = require('./normalise-content.browser')
const normaliseInput = require('./normalise-input')

/*
* Transform one of:
*
* ```
* Bytes (Buffer|ArrayBuffer|TypedArray) [single file]
* Bloby (Blob|File) [single file]
* String [single file]
* { path, content: Bytes } [single file]
* { path, content: Bloby } [single file]
* { path, content: String } [single file]
* { path, content: Iterable<Number> } [single file]
* { path, content: Iterable<Bytes> } [single file]
* { path, content: AsyncIterable<Bytes> } [single file]
* Iterable<Number> [single file]
* Iterable<Bytes> [single file]
* Iterable<Bloby> [multiple files]
* Iterable<String> [multiple files]
* Iterable<{ path, content: Bytes }> [multiple files]
* Iterable<{ path, content: Bloby }> [multiple files]
* Iterable<{ path, content: String }> [multiple files]
* Iterable<{ path, content: Iterable<Number> }> [multiple files]
* Iterable<{ path, content: Iterable<Bytes> }> [multiple files]
* Iterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
* AsyncIterable<Bytes> [single file]
* AsyncIterable<Bloby> [multiple files]
* AsyncIterable<String> [multiple files]
* AsyncIterable<{ path, content: Bytes }> [multiple files]
* AsyncIterable<{ path, content: Bloby }> [multiple files]
* AsyncIterable<{ path, content: String }> [multiple files]
* AsyncIterable<{ path, content: Iterable<Number> }> [multiple files]
* AsyncIterable<{ path, content: Iterable<Bytes> }> [multiple files]
* AsyncIterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
* ```
*
* Into:
*
* ```
* AsyncIterable<{ path, mode, mtime, content: Blob }>
* ```
*
* @param input Object
* @return AsyncInterable<{ path, content: Blob }>
*/
module.exports = (input) => normaliseInput(input, normaliseContent)
49 changes: 49 additions & 0 deletions packages/ipfs-core-utils/src/files/normalise-input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict'

const normaliseContent = require('./normalise-content')
const normaliseInput = require('./normalise-input')

/*
* Transform one of:
*
* ```
* Bytes (Buffer|ArrayBuffer|TypedArray) [single file]
* Bloby (Blob|File) [single file]
* String [single file]
* { path, content: Bytes } [single file]
* { path, content: Bloby } [single file]
* { path, content: String } [single file]
* { path, content: Iterable<Number> } [single file]
* { path, content: Iterable<Bytes> } [single file]
* { path, content: AsyncIterable<Bytes> } [single file]
* Iterable<Number> [single file]
* Iterable<Bytes> [single file]
* Iterable<Bloby> [multiple files]
* Iterable<String> [multiple files]
* Iterable<{ path, content: Bytes }> [multiple files]
* Iterable<{ path, content: Bloby }> [multiple files]
* Iterable<{ path, content: String }> [multiple files]
* Iterable<{ path, content: Iterable<Number> }> [multiple files]
* Iterable<{ path, content: Iterable<Bytes> }> [multiple files]
* Iterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
* AsyncIterable<Bytes> [single file]
* AsyncIterable<Bloby> [multiple files]
* AsyncIterable<String> [multiple files]
* AsyncIterable<{ path, content: Bytes }> [multiple files]
* AsyncIterable<{ path, content: Bloby }> [multiple files]
* AsyncIterable<{ path, content: String }> [multiple files]
* AsyncIterable<{ path, content: Iterable<Number> }> [multiple files]
* AsyncIterable<{ path, content: Iterable<Bytes> }> [multiple files]
* AsyncIterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
* ```
*
* Into:
*
* ```
* AsyncIterable<{ path, mode, mtime, content: AsyncIterable<Buffer> }>
* ```
*
* @param input Object
* @return AsyncInterable<{ path, content: AsyncIterable<Buffer> }>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type annotation is misleading. In browser context return type is AsyncInterable<{ path:string, content:Blob }> it would be nice to reflect that in a comment or change annotation to:

@typedef {AsyncIterable<Buffer> & Blob} Content 
@param {any} input
@returns {AsyncInterable<{ path:string, content: Content }>}

That would mean that return type implements both Blob & AsyncIterable<Buffer> interface which is still not true but it is better and makes tools like vscode able to assist you. If you do want to be true this would be

@type {AsyncInterable<{ path: string, content: AsyncIterable<Buffer> }>|AsyncInterable<{ path: string, content:Blob }>}

But that degrades inference because content ends up being AsyncIterable<Buffer>|Blob.

Copy link
Member Author

@achingbrain achingbrain Jul 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module doesn't convert content to Blob, only to AsyncIterable<Buffer>. index.browser.js converts to Blob.

*/
module.exports = (input) => normaliseInput(input, normaliseContent)
Loading