Skip to content
This repository was archived by the owner on Apr 4, 2019. It is now read-only.

concatenateBuffers delete call doesn't work as intended. #1

Open
datermine opened this issue Nov 17, 2014 · 0 comments
Open

concatenateBuffers delete call doesn't work as intended. #1

datermine opened this issue Nov 17, 2014 · 0 comments

Comments

@datermine
Copy link

An updated version. Let me know what you think. There are a few notes/TODOs. I'm not entirely confident in it, but I'm sure that the delete call from before was not working as intended.

    function concatenateBuffers() {
        var byteLength = 0;
        buffers.forEach(function(buffer) {
            byteLength += buffer.byteLength;
            // TODO(datermine): Figure out if this is necessary.
            if (buffer.byteLength % 2 != 0) {
              byteLength--;
            }
        });
        var tmp = new Uint16Array(byteLength);

        var lastOffset = 0;
        buffers.forEach(function(buffer) {
            // BYTES_PER_ELEMENT == 2 for Uint16Array
            var bufferByteLength = buffer.byteLength;
            if (bufferByteLength % 2 != 0) {
                // NOTE(datermine): Uses to delete, now we use slice.
                // delete buffer[bufferByteLength - 1];
                buffer = buffer.slice(0, bufferByteLength - 1)
                // NOTE(datermine): Once we slice instead of delete, this is really
                // no longer necessary as it's the same as buffer.byteLength
                bufferByteLength -= 1;
            }
            tmp.set(new Uint16Array(buffer), lastOffset);
            // NOTE(datermine): We could just use buffer.byteLength here.
            lastOffset += bufferByteLength;
        });

        var blob = new Blob([tmp.buffer], {
            type: type
        });

        callback(blob);
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant