Skip to content

Support read(0) #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mathiasbynens
Copy link

Allowing .read(0) enables simpler code in cases like the following (which I just ran in to):

reader.read(0x2, function(byteCount, buffer) {
    // The next 2 bytes indicate the size of the string that follows.
    var descriptionLength = buffer.readUIntLE(0, byteCount);
    reader.read(descriptionLength, function(byteCount, buffer) {
        // Imagine lots of code here that reads the string.
        // The exact same code path must be taken if `descriptionLength == 0`,
        // but currently binary-reader doesn’t allow that and forces me to duplicate
        // code or to wrap everything in promises to avoid the sync/async difference.
        // This patch fixes all that by simply allowing `.read(0)`.
    });

Thanks for considering merging this. I really enjoy using this module in my hobby project!

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

Successfully merging this pull request may close these issues.

1 participant