Files
bare-operating-system/kernel/lib/bare/bundles/bareJpeg.js
T
Raven Scott 9bdecc4170
Release rolling / release (push) Successful in 11m16s
Sync Holepunch modules to current clone/npm latest
Bump published pins (compact-encoding 3, bare-fetch/tls/https/ws 3,
bare-subprocess 6, bare-signals 5, corestore 7.12, protomux 3.11,
hypercore-crypto 3.7, bare-runtime 1.31) and regenerate catalogs,
manifests, and kernel/seeder bundles.

Adapt call sites to the new APIs:
- Corestore: explicit session flush before suspend(); treeCache ctor opts
- bare-crypto: KeyObject.export() instead of removed ._key
- Protomux 3.11: wait for fullyOpened()/fullyClosed() on chat channels
- bare-fetch: surface response.type and Headers.getSetCookie
- host snapshots: bare-os 3.9 / bare-posix / bare-fs.statfs frsize
- bare-subprocess 6: optional IPC channel + json serialization

Keep catalog sync from wiping curated pearEntries. Teach the Node test
shim to stub bare-thread/bare-worker (ESM absolute paths) and chain
Bare.on so bare-timers can load. Booter 479, protocol 34, seeder 14.
2026-08-12 20:56:28 -04:00

153 lines
6.0 KiB
JavaScript

var __bare_os_bundle_exports__ = (() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined") return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
var __commonJS = (cb, mod) => function __require2() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// ../../node_modules/bare-jpeg/binding.js
var require_binding = __commonJS({
"../../node_modules/bare-jpeg/binding.js"(exports, module) {
module.exports = __require.addon();
}
});
// ../../node_modules/bare-jpeg/index.js
var require_bare_jpeg = __commonJS({
"../../node_modules/bare-jpeg/index.js"(exports) {
var binding = require_binding();
var MARKER_PREFIX = 255;
var SOI = 216;
var EOI = 217;
var SOS = 218;
var APP0 = 224;
var APP15 = 239;
var COM = 254;
exports.decode = function decode(image) {
const { width, height, data } = binding.decode(image);
return {
width,
height,
data: Buffer.from(data)
};
};
exports.encode = function encode(image, opts = {}) {
const { quality = 90 } = opts;
const buffer = binding.encode(image.data, image.width, image.height, clamp(quality, 0, 100));
return Buffer.from(buffer);
};
exports.readHeader = function readHeader(image) {
const header = binding.readHeader(image);
return {
...header,
markers: header.markers.map(({ marker, data }) => ({
marker,
data: Buffer.from(data)
}))
};
};
exports.replaceMarkers = function replaceMarkers(image, markers = []) {
if (image.length < 2 || image[0] !== MARKER_PREFIX || image[1] !== SOI) {
throw new Error("Invalid JPEG");
}
const output = [image.subarray(0, 2)];
let offset = 2;
let next = 0;
let insertAt = 1;
while (offset < image.length) {
const start = offset;
while (offset < image.length && image[offset] === MARKER_PREFIX) {
offset++;
}
if (offset >= image.length) {
throw new Error("Invalid JPEG");
}
const marker = image[offset];
if (marker === SOS || marker === EOI) {
const leftover = [];
while (next < markers.length) {
leftover.push(buildSegment(markers[next++]));
}
if (leftover.length > 0) {
output.splice(insertAt, 0, ...leftover);
}
output.push(image.subarray(start));
return Buffer.concat(output);
}
if (offset + 2 >= image.length) {
throw new Error("Invalid JPEG");
}
const length = image.readUInt16BE(offset + 1);
const end = offset + 1 + length;
if (length < 2 || end > image.length) {
throw new Error("Invalid JPEG");
}
if (marker >= APP0 && marker <= APP15 || marker === COM) {
if (next < markers.length) {
output.push(buildSegment(markers[next++]));
insertAt = output.length;
}
} else {
output.push(image.subarray(start, end));
}
offset = end;
}
throw new Error("Invalid JPEG");
};
function buildSegment(marker) {
const payload = Buffer.from(marker.data);
const segment = Buffer.allocUnsafe(payload.length + 4);
segment[0] = MARKER_PREFIX;
segment[1] = marker.marker;
segment.writeUInt16BE(payload.length + 2, 2);
payload.copy(segment, 4);
return segment;
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
}
});
// ../../bare-lib-entry-bareJpeg.js
var bare_lib_entry_bareJpeg_exports = {};
__export(bare_lib_entry_bareJpeg_exports, {
default: () => bare_lib_entry_bareJpeg_default
});
var import_bare_jpeg = __toESM(require_bare_jpeg());
var bare_lib_entry_bareJpeg_default = import_bare_jpeg.default;
return __toCommonJS(bare_lib_entry_bareJpeg_exports);
})();
;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};var e=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;var v=e!=null&&typeof e==="object"&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;g[s]["bareJpeg"]=v;})();