Giter Club home page Giter Club logo

Comments (6)

MichalCz avatar MichalCz commented on May 25, 2024

Hi. Thanks for the report.

I have looked into the code quickly and the implementation seems to be there. I'll take a look at that in detail, but the above code doesn't look exactly right. I'm not sure if that's not somehow mispasted, but it appears as if you pass createWriteStream result as the second argument - which looks more like what you'd expect from pipeline method, not from?

from scramjet.

bluelovers avatar bluelovers commented on May 25, 2024

full test code

in console it didn't print 222, mean async function* () is didn't call by BufferStream.from

/**
 * Created by user on 2020/2/21.
 */

import useIPFS from 'use-ipfs';
import { BufferStream } from "scramjet";
import Bluebird from 'bluebird';
import { createWriteStream } from 'fs';
import catIPFS from 'fetch-ipfs/ipfs';
import { outputFile } from 'fs-extra';

useIPFS()
	.then(async ({
		ipfs,
		stop,
	}) =>
	{

		let cid = `Qmdbkxdh8tUA7zcnmcU6Nu7B7bNtubYTBjUHes799tgu83`;
		let timeout = 60 * 1000;

		await catIPFS(cid, ipfs, timeout)
			.then(buf => outputFile('./temp/temp001.png', buf))
			.catch(e => console.error(e))
		;

		return Bluebird.resolve()
			.then(v => BufferStream.from(async function* ()
			{
				console.log(222) // should print 222, but nothing
				for await (const chunk of ipfs.cat(cid, { timeout }))
				{
					console.log(chunk.length); // should print, but nothing
					yield chunk
				}
			}, createWriteStream('./temp/temp3.png')))
			.tapCatch(e => console.error(e))
			.finally(() =>
			{
				console.log(777) // only see 777
				return stop()
			})
	})
;

when work

temp3.png should is, but it is empty
image


this code, for check does u can get image or not

import { outputFile } from 'fs-extra';
import fetchIPFS from 'fetch-ipfs';

fetchIPFS(`Qmdbkxdh8tUA7zcnmcU6Nu7B7bNtubYTBjUHes799tgu83`)
	.then(buf => outputFile('./temp/111.png', buf))
;

from scramjet.

MichalCz avatar MichalCz commented on May 25, 2024

Hey,

Please check this:

/**
 * Created by user on 2020/2/21.
 */

import useIPFS from 'use-ipfs';
import { BufferStream } from "scramjet";
import Bluebird from 'bluebird';
import { createWriteStream } from 'fs';
import { pipeline } from 'stream';
// import catIPFS from 'fetch-ipfs/ipfs';
// import { outputFile } from 'fs-extra';

useIPFS()
	.then(async ({ipfs,stop,}) => {

		let cid = `Qmdbkxdh8tUA7zcnmcU6Nu7B7bNtubYTBjUHes799tgu83`;
		let timeout = 60 * 1000;

		Bluebird.resolve(pipeline(
				BufferStream.from(async function* () {
					console.log(222) // should print 222, but nothing
					for await (const chunk of ipfs.cat(cid, { timeout }))
					{
						console.log(chunk.length); // should print, but nothing
						yield chunk
					}
				})
				createWriteStream('./temp/temp3.png')
			))
			.tapCatch(e => console.error(e))
			.finally(() => {
				console.log(777) // only see 777
				return stop()
			})
	})
;

Actually the generator there is not needed and you can simply pass the result of ipfs.cat:

/**
 * Created by user on 2020/2/21.
 */

import useIPFS from 'use-ipfs';
import { BufferStream } from "scramjet";
import Bluebird from 'bluebird';
import { createWriteStream } from 'fs';
import { pipeline } from 'stream';
// import catIPFS from 'fetch-ipfs/ipfs';
// import { outputFile } from 'fs-extra';

useIPFS()
	.then(async ({ipfs,stop,}) => {

		let cid = `Qmdbkxdh8tUA7zcnmcU6Nu7B7bNtubYTBjUHes799tgu83`;
		let timeout = 60 * 1000;

		Bluebird.resolve(pipeline(
				BufferStream.from(ipfs.cat(cid, { timeout })),
				createWriteStream('./temp/temp3.png')
			))
			.tapCatch(e => console.error(e))
			.finally(() => {
				console.log(777) // only see 777
				return stop()
			})
	})
;

from scramjet.

MichalCz avatar MichalCz commented on May 25, 2024

Let me know if this works for you. :)

from scramjet.

bluelovers avatar bluelovers commented on May 25, 2024
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received WriteStream {
 		Bluebird.resolve(pipeline(
 			// @ts-ignore
 			BufferStream.from(ipfs.cat(cid, { timeout })),
-			createWriteStream('./temp/temp3.png')
+			createWriteStream('./temp/temp3.png'),
+			(err => {console.error(err)})
 			))
 			.tapCatch(e => e && console.error(e))
 			.finally(() => {

thx, it work now

from scramjet.

MichalCz avatar MichalCz commented on May 25, 2024

Great. :)

Actually I forgot this is a callback style function, the best way to use it (as the finally would get executed too soon) would be:

- 		Bluebird.resolve(pipeline(
+ 		Bluebird.promisify(pipeline)(
 			// @ts-ignore
 			BufferStream.from(ipfs.cat(cid, { timeout })),
+			createWriteStream('./temp/temp3.png')
-			createWriteStream('./temp/temp3.png'),
-			(err => {console.error(err)}) 			))
 			.tapCatch(e => e && console.error(e))
 			.finally(() => {

from scramjet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.