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

请帮忙看看为什么这里的read(0)没有把缓存里的东西都清理出来? #29

Open
sakopqiu opened this issue Feb 26, 2018 · 0 comments

Comments

@sakopqiu
Copy link

var Readable = require('stream').Readable;
var rs = Readable();

var c = 97;

rs._read = function () {
    if (c >= 'c'.charCodeAt(0)) return rs.push(null);
    console.log("Pushing " + String.fromCharCode(c) + 'p')
    rs.push(String.fromCharCode(c++) + 'p');
};

rs.on('readable', function () {
    var buf = rs.read(1);
    if (buf) {
        console.dir(buf.toString())
    }
    rs.read(0);
});

rs.on('end', () => {
    console.log("end");
})

打印结果是:
Pushing ap
Pushing bp
'a'
'p'
'b'
也就是说最后在缓存里的一个'p'没有打出来

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

1 participant