diff --git a/packages/ipfs-core-utils/src/files/normalise-content.js b/packages/ipfs-core-utils/src/files/normalise-content.js index 05df86fea9..4d3e4fa9d6 100644 --- a/packages/ipfs-core-utils/src/files/normalise-content.js +++ b/packages/ipfs-core-utils/src/files/normalise-content.js @@ -14,7 +14,14 @@ import { /** * @param {import('./normalise').ToContent} input */ -export async function * normaliseContent (input) { +export async function normaliseContent (input) { + return toAsyncGenerator(input) +} + +/** + * @param {import('./normalise').ToContent} input + */ +async function * toAsyncGenerator (input) { // Bytes | String if (isBytes(input)) { yield toBytes(input) diff --git a/packages/ipfs-core-utils/src/files/normalise.js b/packages/ipfs-core-utils/src/files/normalise.js index df17c037ab..b925a8d792 100644 --- a/packages/ipfs-core-utils/src/files/normalise.js +++ b/packages/ipfs-core-utils/src/files/normalise.js @@ -22,7 +22,7 @@ import { /** * @param {ImportCandidate | ImportCandidateStream} input - * @param {(content:ToContent) => AsyncIterable} normaliseContent + * @param {(content:ToContent) => Promise>} normaliseContent */ // eslint-disable-next-line complexity export async function * normalise (input, normaliseContent) { @@ -72,6 +72,13 @@ export async function * normalise (input, normaliseContent) { return } + // Node ReadableStream + if (value._readableState) { + // @ts-ignore Node readable streams have a `.path` property so we need to pass it as the content + yield * map(peekable, (/** @type {ImportCandidate} */ value) => toFileObject({ content: value }, normaliseContent)) + return + } + // (Async)Iterable // (Async)Iterable // (Async)Iterable<{ path, content }> @@ -103,7 +110,7 @@ export async function * normalise (input, normaliseContent) { /** * @param {ImportCandidate} input - * @param {(content:ToContent) => AsyncIterable} normaliseContent + * @param {(content:ToContent) => Promise>} normaliseContent */ async function toFileObject (input, normaliseContent) { // @ts-ignore - Those properties don't exist on most input types @@ -117,7 +124,6 @@ async function toFileObject (input, normaliseContent) { } if (content) { - // @ts-ignore TODO vmx 2021-03-30 enable again file.content = await normaliseContent(content) } else if (!path) { // Not already a file object with path or content prop // @ts-ignore - input still can be different ToContent diff --git a/packages/ipfs-grpc-client/src/core-api/files/write.js b/packages/ipfs-grpc-client/src/core-api/files/write.js index 74c851c19a..f463a78fd1 100644 --- a/packages/ipfs-grpc-client/src/core-api/files/write.js +++ b/packages/ipfs-grpc-client/src/core-api/files/write.js @@ -12,7 +12,7 @@ import { * @param {*} content */ async function * stream (path, content) { - for await (const buf of normaliseContent(content)) { + for await (const buf of await normaliseContent(content)) { yield { path, content: buf } } }