@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 678 lines 24.3 KB
Raw
1 /**
2 * Scans pack entries out of a BUFFER that starts at an entry boundary and
3 * may end mid-entry (DESIGN §22.7): the unit of work a hashing Worker
4 * receives from the receive-pack pipeline — one spilled part plus the
5 * carry-over of the previous part's incomplete tail.
6 *
7 * Everything that can be settled inside the buffer is settled here:
8 * non-delta entries are inflated and hashed (the expensive part of
9 * ingest), OFS/REF deltas whose base is in the same buffer are applied,
10 * re-deflated and hashed. Deltas whose base lies outside the buffer are
11 * reported as `unresolved` with what the caller needs to settle them
12 * later. The scan stops at the first entry that does not fit; `consumedTo`
13 * is the absolute offset where it starts, so the caller can carry the tail.
14 * An entry only counts as fitting when the buffer extends at least one byte
15 * past it, so the buffer must always end with what FOLLOWS the last entry
16 * to consume (the next part's bytes, or the pack trailer).
17 *
18 * Pure: no store, no I/O. The trailer is NOT verified here (the caller
19 * hashes the whole pack as it streams).
20 */
21 import * as Effect from "effect/Effect";
22 import * as Result from "effect/Result";
23 import * as Schema from "effect/Schema";
24 import { applyDelta } from "./Delta.ts";
25 import {
26 bytesToHex,
27 decodeOfsDeltaOffset,
28 decodeTypeSize,
29 hashObjectSync,
30 ObjectParseError,
31 type ObjectType,
32 type Oid,
33 } from "./ObjectCodec.ts";
34 import { ObjectTooLargeError, PackFormatError } from "./PackParser.ts";
35 import {
36 deflate,
37 inflate,
38 inflateEntrySync,
39 inflateExactSpan,
40 type InflatedEntry,
41 } from "./Zlib.ts";
42
43 export interface ScannedEntry {
44 readonly oid: Oid;
45 readonly type: ObjectType;
46 /** Absolute pack offset of the entry HEADER (what OFS_DELTAs point at). */
47 readonly offset: number;
48 /** Uncompressed size. */
49 readonly size: number;
50 /** Absolute pack offset of the entry's zdata (its header precedes it). */
51 readonly dataOffset: number;
52 /** Compressed span at `dataOffset` — verbatim for non-delta entries. */
53 readonly span: number;
54 /** Set for delta-resolved entries: a fresh deflate to store as the row. */
55 readonly zdata?: Uint8Array | undefined;
56 /** Inflated content for commits, trees and tags (the store parses them). */
57 readonly content?: Uint8Array | undefined;
58 /**
59 * For a delta-resolved entry, its base reference — so a hasher that must
60 * bound its response can demote the entry back to `unresolved`.
61 */
62 readonly baseOffset?: number | undefined;
63 readonly baseOid?: Oid | undefined;
64 }
65
66 export interface UnresolvedDelta {
67 /** Absolute pack offset of the entry header. */
68 readonly offset: number;
69 /** Absolute offset of the delta payload's zdata and its span. */
70 readonly dataOffset: number;
71 readonly span: number;
72 /** The base: an absolute pack offset (OFS_DELTA) or an oid (REF_DELTA). */
73 readonly baseOffset?: number | undefined;
74 readonly baseOid?: Oid | undefined;
75 /** Declared (uncompressed) size of the delta payload. */
76 readonly size: number;
77 }
78
79 export interface ScanResult {
80 /** Absolute offset of the first entry scanned (after resync), or -1 if none. */
81 readonly firstOffset: number;
82 readonly entries: ReadonlyArray<ScannedEntry>;
83 readonly unresolved: ReadonlyArray<UnresolvedDelta>;
84 /** Absolute offset of the first entry NOT consumed (carry from here). */
85 readonly consumedTo: number;
86 /** Entries consumed (resolved + unresolved). */
87 readonly count: number;
88 }
89
90 const isDelta = (type: number) => type === 6 || type === 7;
91
92 /**
93 * Scans `buf`, whose byte 0 is at absolute pack offset `base`. `remaining`
94 * is how many entries the pack still owes (so a trailing partial entry
95 * beyond the count is not mistaken for data); `maxObjectSize` bounds
96 * inflated sizes.
97 */
98 export const scanPart = (
99 buf: Uint8Array,
100 options: {
101 readonly base: number;
102 readonly remaining: number;
103 readonly maxObjectSize: number;
104 /** Resolved content LRU budget for in-buffer delta bases. */
105 readonly cacheBytes?: number | undefined;
106 /**
107 * `buf` does NOT necessarily start at an entry boundary (a raw chunk of
108 * a pack, DESIGN §22.9): find the first boundary with {@link findBoundary}
109 * and scan from there. No boundary within the chunk ⇒ no entries.
110 */
111 readonly resync?: boolean | undefined;
112 },
113 ): Effect.Effect<ScanResult, PackFormatError | ObjectTooLargeError> =>
114 Effect.gen(function* () {
115 const entries: Array<ScannedEntry> = [];
116 const unresolved: Array<UnresolvedDelta> = [];
117 let firstOffset = -1;
118 let startAt = 0;
119 if (options.resync === true) {
120 const found = findBoundary(buf, { maxObjectSize: options.maxObjectSize });
121 if (found === undefined) {
122 return {
123 firstOffset: -1,
124 entries,
125 unresolved,
126 consumedTo: options.base,
127 count: 0,
128 };
129 }
130 startAt = found;
131 firstOffset = options.base + found;
132 }
133 // In resync mode `remaining` is only an upper bound and the buffer may
134 // run into the pack trailer: anything that does not parse as an entry
135 // ends the scan instead of failing it (the pipeline validates the count,
136 // the trailer hash and every object id downstream).
137 const lenient = options.resync === true;
138 // Content of resolved entries in this buffer, by absolute offset and by
139 // oid, for in-buffer delta bases. Bounded; a miss becomes unresolved.
140 const byOffset = new Map<number, { type: ObjectType; content: Uint8Array }>();
141 const byOid = new Map<string, { type: ObjectType; content: Uint8Array }>();
142 let cached = 0;
143 const budget = options.cacheBytes ?? 20 * 1024 * 1024;
144 const remember = (offset: number, oid: Oid, type: ObjectType, content: Uint8Array) => {
145 if (content.length > budget / 4) return;
146 while (cached + content.length > budget && byOffset.size > 0) {
147 const oldest = byOffset.keys().next().value!;
148 const dropped = byOffset.get(oldest)!;
149 byOffset.delete(oldest);
150 cached -= dropped.content.length;
151 }
152 byOffset.set(offset, { type, content });
153 byOid.set(oid, { type, content });
154 cached += content.length;
155 };
156
157 let pos = startAt;
158 let count = 0;
159 while (count < options.remaining && pos < buf.length) {
160 const offset = options.base + pos;
161 const headerResult = yield* Effect.result(
162 Effect.try({
163 try: () => decodeTypeSize(buf, pos),
164 catch: (error) =>
165 PackFormatError.make({
166 reason: Schema.is(ObjectParseError)(error)
167 ? `entry at ${offset}: ${error.reason}`
168 : `entry at ${offset}: ${String(error)}`,
169 }),
170 }),
171 );
172 if (Result.isFailure(headerResult)) {
173 // A header cut by the buffer edge: stop here, carry the tail.
174 if (lenient || buf.length - pos < 16) break;
175 return yield* headerResult.failure;
176 }
177 const header = headerResult.success;
178 if (header.size > options.maxObjectSize) {
179 if (lenient) break;
180 return yield* ObjectTooLargeError.make({
181 size: header.size,
182 limit: options.maxObjectSize,
183 });
184 }
185 let at = header.next;
186 let baseOffset: number | undefined;
187 let baseOid: Oid | undefined;
188 if (header.type === 6) {
189 const ofsResult = yield* Effect.result(
190 Effect.try({
191 try: () => decodeOfsDeltaOffset(buf, at),
192 catch: () => PackFormatError.make({ reason: `entry at ${offset}: bad ofs-delta` }),
193 }),
194 );
195 if (Result.isFailure(ofsResult)) {
196 if (lenient || buf.length - at < 16) break;
197 return yield* ofsResult.failure;
198 }
199 const ofs = ofsResult.success;
200 at = ofs.next;
201 baseOffset = offset - ofs.value;
202 } else if (header.type === 7) {
203 if (at + 20 > buf.length) break;
204 baseOid = bytesToHex(buf.subarray(at, at + 20)) as Oid;
205 at += 20;
206 }
207 const inflated: InflatedEntry | undefined = inflateEntrySync(buf, at, {
208 maxOutput: options.maxObjectSize,
209 expectedSize: header.size,
210 });
211 if (inflated === undefined) {
212 // The compressed stream runs past the buffer (or is corrupt — the
213 // next attempt, with more bytes, decides): carry from this entry.
214 break;
215 }
216 const { bytesConsumed, content: payload } = inflated;
217 // A stream cut inside its last bytes (end-of-block bits, adler32) can
218 // inflate to exactly the declared size without having ended, and the
219 // consumed count would then be short. An entry is complete only when
220 // the buffer extends PAST it: callers always append what follows
221 // (the next part, or the pack trailer for the last one).
222 if (at + bytesConsumed >= buf.length) break;
223 if (payload.length !== header.size) {
224 if (lenient) break;
225 return yield* PackFormatError.make({
226 reason: `entry at ${offset}: inflated ${payload.length} bytes, header declared ${header.size}`,
227 });
228 }
229 const dataOffset = options.base + at;
230 if (!isDelta(header.type)) {
231 const type = header.type as ObjectType;
232 const oid = hashObjectSync(type, payload);
233 entries.push({
234 oid,
235 type,
236 offset,
237 size: payload.length,
238 dataOffset,
239 span: bytesConsumed,
240 content: type === 3 ? undefined : payload,
241 });
242 remember(offset, oid, type, payload);
243 } else {
244 const found = baseOffset !== undefined ? byOffset.get(baseOffset) : byOid.get(baseOid!);
245 if (found === undefined) {
246 unresolved.push({
247 offset,
248 dataOffset,
249 span: bytesConsumed,
250 baseOffset,
251 baseOid,
252 size: header.size,
253 });
254 } else {
255 const content = yield* applyDelta(found.content, payload).pipe(
256 Effect.mapError((error) =>
257 PackFormatError.make({
258 reason: `entry at ${offset}: ${error.reason}`,
259 }),
260 ),
261 );
262 if (content.length > options.maxObjectSize) {
263 return yield* ObjectTooLargeError.make({
264 size: content.length,
265 limit: options.maxObjectSize,
266 });
267 }
268 const oid = hashObjectSync(found.type, content);
269 const zdata = yield* deflate(content).pipe(
270 Effect.mapError((error) => PackFormatError.make({ reason: error.reason })),
271 );
272 entries.push({
273 oid,
274 type: found.type,
275 offset,
276 size: content.length,
277 dataOffset,
278 span: bytesConsumed,
279 zdata,
280 content: found.type === 3 ? undefined : content,
281 baseOffset,
282 baseOid,
283 });
284 remember(offset, oid, found.type, content);
285 }
286 }
287 pos = at + bytesConsumed;
288 count += 1;
289 }
290 return {
291 firstOffset: firstOffset >= 0 ? firstOffset : entries.length > 0 ? options.base : -1,
292 entries,
293 unresolved,
294 consumedTo: options.base + pos,
295 count,
296 };
297 });
298
299 /** One entry's coordinates from a boundary-only scan (DESIGN §22.8). */
300 export interface EntryBounds {
301 /** Absolute pack offset of the entry header. */
302 readonly offset: number;
303 /** 1–4 for full objects, 6/7 for OFS/REF deltas. */
304 readonly type: number;
305 /** Declared (uncompressed) size. */
306 readonly size: number;
307 /** Absolute offset and length of the compressed span. */
308 readonly dataOffset: number;
309 readonly span: number;
310 readonly baseOffset?: number | undefined;
311 readonly baseOid?: Oid | undefined;
312 }
313
314 export interface BoundsResult {
315 readonly entries: ReadonlyArray<EntryBounds>;
316 /** Absolute offset of the first entry NOT consumed (carry from here). */
317 readonly consumedTo: number;
318 }
319
320 /**
321 * Boundary-only scan (DESIGN §22.8): finds every entry's compressed span in
322 * `buf` without hashing or resolving anything — the one inherently
323 * sequential step of pack ingest (a stream's end is only known by inflating
324 * it). With spans known, hashing every part can run in parallel and can
325 * inflate exact slices with the cheap one-shot path. Same contract as
326 * {@link scanPart}: `buf` starts at an entry boundary and must extend past
327 * the last entry to consume.
328 */
329 export const scanBounds = (
330 buf: Uint8Array,
331 options: {
332 readonly base: number;
333 readonly remaining: number;
334 readonly maxObjectSize: number;
335 },
336 ): Effect.Effect<BoundsResult, PackFormatError | ObjectTooLargeError> =>
337 Effect.gen(function* () {
338 const entries: Array<EntryBounds> = [];
339 let pos = 0;
340 let count = 0;
341 while (count < options.remaining && pos < buf.length) {
342 const offset = options.base + pos;
343 const headerResult = yield* Effect.result(
344 Effect.try({
345 try: () => decodeTypeSize(buf, pos),
346 catch: (error) =>
347 PackFormatError.make({
348 reason: Schema.is(ObjectParseError)(error)
349 ? `entry at ${offset}: ${error.reason}`
350 : `entry at ${offset}: ${String(error)}`,
351 }),
352 }),
353 );
354 if (Result.isFailure(headerResult)) {
355 if (buf.length - pos < 16) break;
356 return yield* headerResult.failure;
357 }
358 const header = headerResult.success;
359 if (header.size > options.maxObjectSize) {
360 return yield* ObjectTooLargeError.make({
361 size: header.size,
362 limit: options.maxObjectSize,
363 });
364 }
365 let at = header.next;
366 let baseOffset: number | undefined;
367 let baseOid: Oid | undefined;
368 if (header.type === 6) {
369 const ofsResult = yield* Effect.result(
370 Effect.try({
371 try: () => decodeOfsDeltaOffset(buf, at),
372 catch: () => PackFormatError.make({ reason: `entry at ${offset}: bad ofs-delta` }),
373 }),
374 );
375 if (Result.isFailure(ofsResult)) {
376 if (buf.length - at < 16) break;
377 return yield* ofsResult.failure;
378 }
379 const ofs = ofsResult.success;
380 at = ofs.next;
381 baseOffset = offset - ofs.value;
382 } else if (header.type === 7) {
383 if (at + 20 > buf.length) break;
384 baseOid = bytesToHex(buf.subarray(at, at + 20)) as Oid;
385 at += 20;
386 }
387 const inflated = inflateEntrySync(buf, at, {
388 maxOutput: options.maxObjectSize,
389 expectedSize: header.size,
390 });
391 if (inflated === undefined) break;
392 if (at + inflated.bytesConsumed >= buf.length) break;
393 if (inflated.content.length !== header.size) {
394 return yield* PackFormatError.make({
395 reason: `entry at ${offset}: inflated ${inflated.content.length} bytes, header declared ${header.size}`,
396 });
397 }
398 entries.push({
399 offset,
400 type: header.type,
401 size: header.size,
402 dataOffset: options.base + at,
403 span: inflated.bytesConsumed,
404 baseOffset,
405 baseOid,
406 });
407 pos = at + inflated.bytesConsumed;
408 count += 1;
409 }
410 return { entries, consumedTo: options.base + pos };
411 });
412
413 /**
414 * Hashes entries whose spans are already known (DESIGN §22.8): the parallel
415 * half. `bounds` addresses spans inside `buf` (absolute offsets; `base` is
416 * `buf[0]`'s offset). Non-delta entries are inflated with the one-shot
417 * path and hashed; deltas whose base is among these entries (or already
418 * resolved here) are applied, re-deflated and hashed; the rest are reported
419 * unresolved.
420 */
421 export const hashBounds = (
422 buf: Uint8Array,
423 bounds: ReadonlyArray<EntryBounds>,
424 options: {
425 readonly base: number;
426 readonly maxObjectSize: number;
427 readonly cacheBytes?: number | undefined;
428 },
429 ): Effect.Effect<ScanResult, PackFormatError | ObjectTooLargeError> =>
430 Effect.gen(function* () {
431 const entries: Array<ScannedEntry> = [];
432 const unresolved: Array<UnresolvedDelta> = [];
433 const byOffset = new Map<number, { type: ObjectType; content: Uint8Array }>();
434 const byOid = new Map<string, { type: ObjectType; content: Uint8Array }>();
435 const inflateExact = (b: EntryBounds) =>
436 inflateExactSpan(
437 buf.subarray(b.dataOffset - options.base, b.dataOffset - options.base + b.span),
438 b.size,
439 ).pipe(
440 Effect.mapError((error) =>
441 PackFormatError.make({
442 reason: `entry at ${b.offset}: ${error.reason}`,
443 }),
444 ),
445 );
446 for (const b of bounds) {
447 const payload = yield* inflateExact(b);
448 if (!isDelta(b.type)) {
449 const type = b.type as ObjectType;
450 const oid = hashObjectSync(type, payload);
451 entries.push({
452 oid,
453 type,
454 offset: b.offset,
455 size: payload.length,
456 dataOffset: b.dataOffset,
457 span: b.span,
458 content: type === 3 ? undefined : payload,
459 });
460 byOffset.set(b.offset, { type, content: payload });
461 byOid.set(oid, { type, content: payload });
462 continue;
463 }
464 const found = b.baseOffset !== undefined ? byOffset.get(b.baseOffset) : byOid.get(b.baseOid!);
465 if (found === undefined) {
466 unresolved.push({
467 offset: b.offset,
468 dataOffset: b.dataOffset,
469 span: b.span,
470 baseOffset: b.baseOffset,
471 baseOid: b.baseOid,
472 size: b.size,
473 });
474 continue;
475 }
476 const content = yield* applyDelta(found.content, payload).pipe(
477 Effect.mapError((error) =>
478 PackFormatError.make({
479 reason: `entry at ${b.offset}: ${error.reason}`,
480 }),
481 ),
482 );
483 if (content.length > options.maxObjectSize) {
484 return yield* ObjectTooLargeError.make({
485 size: content.length,
486 limit: options.maxObjectSize,
487 });
488 }
489 const oid = hashObjectSync(found.type, content);
490 const zdata = yield* deflate(content).pipe(
491 Effect.mapError((error) => PackFormatError.make({ reason: error.reason })),
492 );
493 entries.push({
494 oid,
495 type: found.type,
496 offset: b.offset,
497 size: content.length,
498 dataOffset: b.dataOffset,
499 span: b.span,
500 zdata,
501 content: found.type === 3 ? undefined : content,
502 });
503 byOffset.set(b.offset, { type: found.type, content });
504 byOid.set(oid, { type: found.type, content });
505 }
506 const last = bounds[bounds.length - 1];
507 return {
508 firstOffset: bounds[0]?.offset ?? -1,
509 entries,
510 unresolved,
511 consumedTo: last === undefined ? options.base : last.dataOffset + last.span,
512 count: bounds.length,
513 };
514 });
515
516 /**
517 * Finds the first entry boundary inside `buf` (DESIGN §22.9): the parallel
518 * answer to "where does an entry start?", so chunks of a pack can be scanned
519 * independently. A position is a boundary when it decodes as an entry
520 * header, its stream inflates to exactly the declared size, AND the entry
521 * that follows does too — two consecutive coincidences on arbitrary bytes
522 * are not a realistic false positive, and the pack trailer plus per-object
523 * hashing verify everything downstream regardless.
524 *
525 * Candidates are filtered cheaply: a deflate stream from git starts with
526 * the zlib header `0x78` followed by one of four FLG bytes, right after a
527 * 1–10 byte varint header. Returns the offset into `buf`, or `undefined`
528 * when no boundary lies within `maxSearch` bytes — the whole chunk by
529 * default: a part whose head is inside one large entry still has its own
530 * entries to hash, and a part that reports no boundary is hashed serially
531 * as a region by the caller (a 10 MB blob spanning three parts once cost
532 * a whole part's worth of serial hashing under a 1 MiB limit).
533 */
534 export const findBoundary = (
535 buf: Uint8Array,
536 options: {
537 readonly maxObjectSize: number;
538 readonly maxSearch?: number | undefined;
539 },
540 ): number | undefined => {
541 const limit = Math.min(buf.length, options.maxSearch ?? buf.length);
542 const isZlibHeader = (i: number) =>
543 i + 1 < buf.length &&
544 buf[i] === 0x78 &&
545 (buf[i + 1] === 0x01 || buf[i + 1] === 0x5e || buf[i + 1] === 0x9c || buf[i + 1] === 0xda);
546 const parses = (pos: number): number | undefined => {
547 let header;
548 try {
549 header = decodeTypeSize(buf, pos);
550 } catch {
551 return undefined;
552 }
553 if (header.type < 1 || header.type > 7) return undefined;
554 if (header.size > options.maxObjectSize) return undefined;
555 let at = header.next;
556 if (header.type === 6) {
557 try {
558 at = decodeOfsDeltaOffset(buf, at).next;
559 } catch {
560 return undefined;
561 }
562 } else if (header.type === 7) {
563 at += 20;
564 }
565 if (!isZlibHeader(at)) return undefined;
566 const inflated = inflateEntrySync(buf, at, {
567 maxOutput: options.maxObjectSize,
568 expectedSize: header.size,
569 });
570 if (inflated === undefined || inflated.content.length !== header.size) return undefined;
571 const end = at + inflated.bytesConsumed;
572 return end >= buf.length ? undefined : end;
573 };
574 for (let pos = 0; pos < limit; pos++) {
575 // Cheap pre-filter: a zlib header must appear within the next 32 bytes
576 // (header varint + optional base ref).
577 let plausible = false;
578 for (let k = pos + 1; k <= pos + 32 && k < buf.length; k++) {
579 if (isZlibHeader(k)) {
580 plausible = true;
581 break;
582 }
583 }
584 if (!plausible) continue;
585 const next = parses(pos);
586 if (next === undefined) continue;
587 // Second entry must parse too (or the buffer ends right after — accept
588 // only if the first entry ended cleanly inside the buffer).
589 const after = parses(next);
590 if (after !== undefined) return pos;
591 }
592 return undefined;
593 };
594
595 // ── delta resolution as a job (DESIGN §22.13) ──────────────────────────────
596
597 /** One base a batch of delta jobs refers to: zlib bytes, or already-inflated content. */
598 export interface DeltaBase {
599 readonly bytes: Uint8Array;
600 readonly isContent: boolean;
601 }
602
603 /** One delta to apply: its base (by index into the batch's bases) and its zlib bytes. */
604 export interface DeltaJob {
605 readonly id: number;
606 readonly type: ObjectType;
607 readonly base: number;
608 readonly delta: Uint8Array;
609 }
610
611 /** A resolved delta: the object's oid and a fresh deflate; content for non-blobs. */
612 export interface DeltaResolved {
613 readonly id: number;
614 readonly oid: Oid;
615 readonly size: number;
616 readonly zdata: Uint8Array;
617 readonly content?: Uint8Array | undefined;
618 }
619
620 /**
621 * Applies a batch of deltas whose bases the caller supplies — the work the
622 * receiver would otherwise do itself for every delta whose base lies in
623 * another chunk. Pure over its inputs, so a hasher isolate can run it.
624 */
625 export const resolveDeltas = (
626 bases: ReadonlyArray<DeltaBase>,
627 jobs: ReadonlyArray<DeltaJob>,
628 options: { readonly maxObjectSize: number },
629 ): Effect.Effect<Array<DeltaResolved>, PackFormatError | ObjectTooLargeError> =>
630 Effect.gen(function* () {
631 const inflated = new Map<number, Uint8Array>();
632 const baseContent = (index: number) =>
633 Effect.gen(function* () {
634 const cached = inflated.get(index);
635 if (cached !== undefined) return cached;
636 const base = bases[index];
637 if (base === undefined) {
638 return yield* PackFormatError.make({
639 reason: `delta base ${index} missing`,
640 });
641 }
642 const content = base.isContent
643 ? base.bytes
644 : yield* inflate(base.bytes).pipe(
645 Effect.mapError((error) => PackFormatError.make({ reason: error.reason })),
646 );
647 inflated.set(index, content);
648 return content;
649 });
650 const out: Array<DeltaResolved> = [];
651 for (const job of jobs) {
652 const base = yield* baseContent(job.base);
653 const delta = yield* inflate(job.delta).pipe(
654 Effect.mapError((error) => PackFormatError.make({ reason: error.reason })),
655 );
656 const content = yield* applyDelta(base, delta).pipe(
657 Effect.mapError((error) => PackFormatError.make({ reason: error.reason })),
658 );
659 if (content.length > options.maxObjectSize) {
660 return yield* ObjectTooLargeError.make({
661 size: content.length,
662 limit: options.maxObjectSize,
663 });
664 }
665 const oid = hashObjectSync(job.type, content);
666 const zdata = yield* deflate(content).pipe(
667 Effect.mapError((error) => PackFormatError.make({ reason: error.reason })),
668 );
669 out.push({
670 id: job.id,
671 oid,
672 size: content.length,
673 zdata,
674 content: job.type === 3 ? undefined : content,
675 });
676 }
677 return out;
678 });