Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:48:26+00:00 2026-06-17T22:48:26+00:00

I want to pass a stream as argument to a function and use it

  • 0

I want to pass a stream as argument to a function and use it in an async callback but it is destroyed (stream.readable is false)

for example:

var test = require('./test');
var file = fs.createReadStream('./file.txt');
test(file, console.log);

and in test.js:

module.exports = function(stream, callback) {
    //stream.pipe(process.stdout); ///////// STREAM IS READABLE HERE 
    doSomething('abc', function(err) {
         stream.pipe(process.stdout); ///////// STREAM IS NOT READABLE HERE
         callback(err);
    });
};
enter code here

why is this happening ?
what can I do to use it in the callback ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:48:27+00:00Added an answer on June 17, 2026 at 10:48 pm

    This happens because stream ends before you trying to pipe it. In the first place stream is readable because you synchronous code still working. In the second place (inside of callback) stream already ended because callback may be executed after several ticks in future. You need to pasue your streem if you want to read it in future. This code should work:

    var test = require('./test');
    var file = fs.createReadStream('./file.txt');
    file.pause();
    test(file, console.log);
    

    test.js

    module.exports = function(stream, callback) {
        doSomething('abc', function(err) {
             stream.resume();
             stream.pipe(process.stdout);
             callback(err);
        });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass data from second tab to first tab using delegates.But delegate
I want to pass sbcl a string as a single argument using a bashcript
I have a function that accepts File as an argument. I don't want to
I have an a FILE STREAM that I want to pass to an EXE
I want pass a class-instace to a method of an other and be sure
My data is just number, I want pass it from VC1 to VC2 for
I want to pass an ImageIcon instance by value as we know that by
I want to pass '#' to the query string like ?page.aspx?someParam=1234#5 .
I want to pass a string that contains few words to jQuery when click
I want to pass an uninitialized object pointer to some method. Within that method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.