Comments (6)
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.
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
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.
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.
Let me know if this works for you. :)
from scramjet.
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.
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)
- MultiStream.map(...).mux is not a function HOT 2
- Parsing CSV files of certain arbitrary lengths suddenly stops HOT 7
- StringStream.whenEnd produces UnhandledPromiseRejectionWarning on error HOT 4
- Using scramjet to concate and split data received with socket HOT 10
- DataStream.toJSONArray causes an exception on empty input HOT 5
- Fail when plugin adds a new class twice HOT 1
- I would like to pin this repository to my GH profile HOT 1
- Stateful stream transformation HOT 3
- Class 'PromiseTransform' incorrectly implements class 'Readable' HOT 6
- DataStream.distribute causes ReferenceError when using external function inside HOT 1
- Iterating each chunk with async function with stopping stream HOT 2
- Runner failed error HOT 3
- Cannot stop instance HOT 3
- 'Sequence unpack failed' issue HOT 9
- Instance timeout
- Runner failed error HOT 2
- Slow execution time of reading a big file HOT 4
- Drag n drop into 'add sequence' multiple times spams seq list HOT 1
- Add sequence's remove button on the list page
- Getting error Class 'PromiseTransform' incorrectly implements class 'Readable' and 'Writable' HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scramjet.