Browse Source

Fix embedding extraction for files with multiple chunks

pull/46/head
coomdev 2 years ago
parent
commit
5331ee3184
  1. 2
      main.meta.js
  2. 10
      main.user.js
  3. 9
      src/pngv3.ts

2
main.meta.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.173
// @version 0.174
// @description uhh
// @author You
// @match https://boards.4channel.org/*

10
main.user.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.173
// @version 0.174
// @description uhh
// @author You
// @match https://boards.4channel.org/*
@ -81,7 +81,7 @@
var define_BUILD_VERSION_default;
var init_define_BUILD_VERSION = __esm({
"<define:BUILD_VERSION>"() {
define_BUILD_VERSION_default = [0, 173];
define_BUILD_VERSION_default = [0, 174];
}
});
@ -14002,6 +14002,7 @@
var extract = async (png) => {
const reader = BufferReadStream(png).getReader();
const sneed = new PNGDecoder(reader);
const ret = [];
try {
for await (const [name, chunk, crc, offset] of sneed.chunks()) {
let buff;
@ -14009,12 +14010,13 @@
case "tEXt":
buff = await chunk();
if (buff.slice(4, 4 + CUM3.length).equals(CUM3)) {
return await decodeCoom3Payload(buff.slice(4 + CUM3.length));
const k = await decodeCoom3Payload(buff.slice(4 + CUM3.length));
ret.push(...k.filter((e) => e).map((e) => e));
}
break;
case "IDAT":
case "IEND":
return;
return ret;
default:
break;
}

9
src/pngv3.ts

@ -1,5 +1,5 @@
import { Buffer } from "buffer";
import type { ImageProcessor } from "./main";
import type { EmbeddedFile, ImageProcessor } from "./main";
import { PNGDecoder, PNGEncoder } from "./png";
import { buildPeeFile, decodeCoom3Payload, fireNotification, uploadFiles } from "./utils";
@ -18,6 +18,8 @@ const BufferReadStream = (b: Buffer) => {
const extract = async (png: Buffer) => {
const reader = BufferReadStream(png).getReader();
const sneed = new PNGDecoder(reader);
const ret: EmbeddedFile[] = [];
try {
for await (const [name, chunk, crc, offset] of sneed.chunks()) {
let buff: Buffer;
@ -26,13 +28,14 @@ const extract = async (png: Buffer) => {
case 'tEXt':
buff = await chunk();
if (buff.slice(4, 4 + CUM3.length).equals(CUM3)) {
return await decodeCoom3Payload(buff.slice(4 + CUM3.length));
const k = await decodeCoom3Payload(buff.slice(4 + CUM3.length));
ret.push(...k.filter(e => e).map(e => e as EmbeddedFile));
}
break;
case 'IDAT':
// eslint-disable-next-line no-fallthrough
case 'IEND':
return;
return ret;
// eslint-disable-next-line no-fallthrough
default:
break;

Loading…
Cancel
Save