MCPcopy
hub / github.com/gchq/CyberChef / extractPNG

Function extractPNG

src/core/lib/FileSignatures.mjs:3034–3053  ·  view source on GitHub ↗
(bytes, offset)

Source from the content-addressed store, hash-verified

3032 * @returns {Uint8Array}
3033 */
3034export function extractPNG(bytes, offset) {
3035 const stream = new Stream(bytes.slice(offset));
3036
3037 // Move past signature to first chunk
3038 stream.moveForwardsBy(8);
3039
3040 let chunkSize = 0,
3041 chunkType = "";
3042
3043 while (chunkType !== "IEND") {
3044 chunkSize = stream.readInt(4, "be");
3045 chunkType = stream.readString(4);
3046
3047 // Chunk data size + CRC checksum
3048 stream.moveForwardsBy(chunkSize + 4);
3049 }
3050
3051
3052 return stream.carve();
3053}
3054
3055
3056/**

Callers

nothing calls this directly

Calls 4

moveForwardsByMethod · 0.95
readIntMethod · 0.95
readStringMethod · 0.95
carveMethod · 0.95

Tested by

no test coverage detected