roxify 1.1.9 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +82 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1654,6 +1654,88 @@ export async function listFilesInPng(pngBuf) {
|
|
|
1654
1654
|
catch (e) { }
|
|
1655
1655
|
}
|
|
1656
1656
|
catch (e) { }
|
|
1657
|
+
try {
|
|
1658
|
+
const reconstructed = await cropAndReconstitute(pngBuf);
|
|
1659
|
+
try {
|
|
1660
|
+
const { data, info } = await sharp(reconstructed)
|
|
1661
|
+
.ensureAlpha()
|
|
1662
|
+
.raw()
|
|
1663
|
+
.toBuffer({ resolveWithObject: true });
|
|
1664
|
+
const currentWidth = info.width;
|
|
1665
|
+
const currentHeight = info.height;
|
|
1666
|
+
const rawRGB = Buffer.alloc(currentWidth * currentHeight * 3);
|
|
1667
|
+
for (let i = 0; i < currentWidth * currentHeight; i++) {
|
|
1668
|
+
rawRGB[i * 3] = data[i * 4];
|
|
1669
|
+
rawRGB[i * 3 + 1] = data[i * 4 + 1];
|
|
1670
|
+
rawRGB[i * 3 + 2] = data[i * 4 + 2];
|
|
1671
|
+
}
|
|
1672
|
+
const found = rawRGB.indexOf(PIXEL_MAGIC);
|
|
1673
|
+
if (found !== -1) {
|
|
1674
|
+
let idx = found + PIXEL_MAGIC.length;
|
|
1675
|
+
if (idx + 2 <= rawRGB.length) {
|
|
1676
|
+
const version = rawRGB[idx++];
|
|
1677
|
+
const nameLen = rawRGB[idx++];
|
|
1678
|
+
if (process.env.ROX_DEBUG)
|
|
1679
|
+
console.log('listFilesInPng (reconstructed): pixel version', version, 'nameLen', nameLen);
|
|
1680
|
+
if (nameLen > 0 && idx + nameLen <= rawRGB.length) {
|
|
1681
|
+
idx += nameLen;
|
|
1682
|
+
}
|
|
1683
|
+
if (idx + 4 <= rawRGB.length) {
|
|
1684
|
+
const payloadLen = rawRGB.readUInt32BE(idx);
|
|
1685
|
+
idx += 4;
|
|
1686
|
+
const afterPayload = idx + payloadLen;
|
|
1687
|
+
if (afterPayload <= rawRGB.length) {
|
|
1688
|
+
if (afterPayload + 8 <= rawRGB.length) {
|
|
1689
|
+
const marker = rawRGB
|
|
1690
|
+
.slice(afterPayload, afterPayload + 4)
|
|
1691
|
+
.toString('utf8');
|
|
1692
|
+
if (marker === 'rXFL') {
|
|
1693
|
+
const jsonLen = rawRGB.readUInt32BE(afterPayload + 4);
|
|
1694
|
+
const jsonStart = afterPayload + 8;
|
|
1695
|
+
const jsonEnd = jsonStart + jsonLen;
|
|
1696
|
+
if (jsonEnd <= rawRGB.length) {
|
|
1697
|
+
const jsonBuf = rawRGB.slice(jsonStart, jsonEnd);
|
|
1698
|
+
const files = JSON.parse(jsonBuf.toString('utf8'));
|
|
1699
|
+
return files.sort();
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
catch (e) { }
|
|
1709
|
+
try {
|
|
1710
|
+
const chunks = extract(reconstructed);
|
|
1711
|
+
const fileListChunk = chunks.find((c) => c.name === 'rXFL');
|
|
1712
|
+
if (fileListChunk) {
|
|
1713
|
+
const data = Buffer.isBuffer(fileListChunk.data)
|
|
1714
|
+
? fileListChunk.data
|
|
1715
|
+
: Buffer.from(fileListChunk.data);
|
|
1716
|
+
const files = JSON.parse(data.toString('utf8'));
|
|
1717
|
+
return files.sort();
|
|
1718
|
+
}
|
|
1719
|
+
const metaChunk = chunks.find((c) => c.name === CHUNK_TYPE);
|
|
1720
|
+
if (metaChunk) {
|
|
1721
|
+
const dataBuf = Buffer.isBuffer(metaChunk.data)
|
|
1722
|
+
? metaChunk.data
|
|
1723
|
+
: Buffer.from(metaChunk.data);
|
|
1724
|
+
const markerIdx = dataBuf.indexOf(Buffer.from('rXFL'));
|
|
1725
|
+
if (markerIdx !== -1 && markerIdx + 8 <= dataBuf.length) {
|
|
1726
|
+
const jsonLen = dataBuf.readUInt32BE(markerIdx + 4);
|
|
1727
|
+
const jsonStart = markerIdx + 8;
|
|
1728
|
+
const jsonEnd = jsonStart + jsonLen;
|
|
1729
|
+
if (jsonEnd <= dataBuf.length) {
|
|
1730
|
+
const files = JSON.parse(dataBuf.slice(jsonStart, jsonEnd).toString('utf8'));
|
|
1731
|
+
return files.sort();
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
catch (e) { }
|
|
1737
|
+
}
|
|
1738
|
+
catch (e) { }
|
|
1657
1739
|
try {
|
|
1658
1740
|
const chunks = extract(pngBuf);
|
|
1659
1741
|
const fileListChunk = chunks.find((c) => c.name === 'rXFL');
|
package/package.json
CHANGED