Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Sep 24, 2023
1 parent 7c3f881 commit ae5c025
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {IPngIhdr} from './types';

const PNG_MAGIC = [137, 80, 78, 71, 13, 10, 26, 10];

/**
* Concatenate multiple Uint8Array together.
*
Expand Down Expand Up @@ -28,17 +30,10 @@ export function concatUint8Arrays(arrays: Readonly<Readonly<Uint8Array>[]>) {
*/
export function pngIhdr(data: Readonly<Uint8Array>): IPngIhdr {
let i = 0;
if (
data[i++] !== 137 ||
data[i++] !== 80 ||
data[i++] !== 78 ||
data[i++] !== 71 ||
data[i++] !== 13 ||
data[i++] !== 10 ||
data[i++] !== 26 ||
data[i++] !== 10
) {
throw new Error('Invalid PNG header signature');
for (; i < 8; i++) {
if (data[i] !== PNG_MAGIC[i]) {
throw new Error('Invalid PNG header signature');
}
}

// Seek out IHDR tag, which should be first (spec requires, some ignore).
Expand Down

0 comments on commit ae5c025

Please sign in to comment.