Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 6 -- 03 Serve Static content pauses #38

Open
p-donahue opened this issue Aug 28, 2017 · 3 comments
Open

Chapter 6 -- 03 Serve Static content pauses #38

p-donahue opened this issue Aug 28, 2017 · 3 comments

Comments

@p-donahue
Copy link

The chapter 6 code for "Serve Static Content Pauses" crashes with the error:

TypeError: First argument must be a string or Buffer
when it calls:
if (!res.write(data))

@p-donahue
Copy link
Author

The function needs the if(data) block used previously.

rs.on('readable', () => {
    var data = rs.read();
    if(data) {
         if (!res.write(data)) {
            rs.pause();
         }
    }
});

I'd love a better explanation of why its needed.

@marcwan
Copy link
Owner

marcwan commented Sep 27, 2017

Hi!

Thanks for the note. That's behaviour I haven't seen before. I guess there is now a case where you get a readable, but there's no data to actually read. I suspect the "readable" event is still fired to let you know that it's finished or something.

What version of node is this for? I wonder if it's a change.

@smallbonelu
Copy link

I've the same issue when I try to refresh the page. My node version is v8.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants