GIF: clean up reading of trailer block
This commit is contained in:
parent
40c7091386
commit
253b8e272c
|
@ -226,6 +226,19 @@ const readExtensionBlock = (bytes, startingOffset) => {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} bytes
|
||||
* @param {number} offset
|
||||
* @returns {{ node: GifNode, newOffset: number }}
|
||||
*/
|
||||
const readTrailerBlock = (bytes, offset) => ({
|
||||
newOffset: offset + 1,
|
||||
node: {
|
||||
type: GifNodeType.gifTerminator,
|
||||
bytes: bytes.subarray(offset, offset + 1),
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} bytes
|
||||
* @returns {null | GifNode} The root node of the GIF tree, or null if the GIF is invalid.
|
||||
|
@ -302,8 +315,7 @@ export default (bytes) => {
|
|||
offset += sizeOfGlobalColorTableInBytes;
|
||||
}
|
||||
|
||||
readingBlocks:
|
||||
while (true) {
|
||||
while (offset < bytes.byteLength) {
|
||||
const blockType = bytes[offset];
|
||||
|
||||
let readerFn;
|
||||
|
@ -315,11 +327,8 @@ export default (bytes) => {
|
|||
readerFn = readExtensionBlock;
|
||||
break;
|
||||
case BLOCK_TYPE_TRAILER:
|
||||
children.push({
|
||||
type: GifNodeType.gifTerminator,
|
||||
bytes: bytes.subarray(offset, offset + 1),
|
||||
});
|
||||
break readingBlocks;
|
||||
readerFn = readTrailerBlock;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown GIF block type: ${blockType}`);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue