react-native-update-cli 2.22.5 → 2.22.7

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.
@@ -40,6 +40,7 @@ exports.DEFAULT_CACHE_MAX_FILES = exports.DEFAULT_CACHE_MAX_BYTES = exports.BUND
40
40
  exports.classifyHermesCommand = classifyHermesCommand;
41
41
  exports.sha256Hex = sha256Hex;
42
42
  exports.probeHbcVersion = probeHbcVersion;
43
+ exports.bundleEntryMatcher = bundleEntryMatcher;
43
44
  exports.extractBundleFromArchive = extractBundleFromArchive;
44
45
  exports.cacheDir = cacheDir;
45
46
  exports.tmpDir = tmpDir;
@@ -51,6 +52,7 @@ exports.cleanCache = cleanCache;
51
52
  exports.cacheStats = cacheStats;
52
53
  exports.cleanStaleTmp = cleanStaleTmp;
53
54
  exports.downloadToFile = downloadToFile;
55
+ exports.fetchBaseBundle = fetchBaseBundle;
54
56
  exports.resolveHermesBase = resolveHermesBase;
55
57
  exports.hermescArgsWithBase = hermescArgsWithBase;
56
58
  exports.hermesBaseMeta = hermesBaseMeta;
@@ -76,6 +78,7 @@ const constants_1 = require("./constants");
76
78
  const hbcTransform_1 = require("./hbcTransform");
77
79
  const i18n_1 = require("./i18n");
78
80
  const zip_entries_1 = require("./zip-entries");
81
+ const zip_range_1 = require("./zip-range");
79
82
  // ---------------------------------------------------------------------------
80
83
  // hermesc gating
81
84
  // ---------------------------------------------------------------------------
@@ -163,8 +166,60 @@ function classifyHermesCommand(hermesCommand) {
163
166
  function sha256Hex(data) {
164
167
  return (0, crypto_1.createHash)('sha256').update(data).digest('hex');
165
168
  }
166
- /** Compile an empty file to learn which HBC version this hermesc emits. */
169
+ const PROBE_CACHE_FILE = 'hbc-versions.json';
170
+ const PROBE_CACHE_ENTRIES = 16;
171
+ /** identity of a hermesc binary for the probe cache: path + size + mtime */
172
+ function probeCacheKey(hermesCommand) {
173
+ try {
174
+ const stat = fs_extra_1.default.statSync(hermesCommand);
175
+ return `${path_1.default.resolve(hermesCommand)}|${stat.size}|${Math.floor(stat.mtimeMs)}`;
176
+ }
177
+ catch {
178
+ return null;
179
+ }
180
+ }
181
+ function readProbeCache() {
182
+ try {
183
+ const parsed = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), 'utf8'));
184
+ return parsed && typeof parsed === 'object' ? parsed : {};
185
+ }
186
+ catch {
187
+ return {};
188
+ }
189
+ }
190
+ function writeProbeCache(entries) {
191
+ try {
192
+ const keys = Object.keys(entries);
193
+ // keep the most recently inserted entries only
194
+ const trimmed = Object.fromEntries(keys.slice(-PROBE_CACHE_ENTRIES).map((key) => [key, entries[key]]));
195
+ fs_extra_1.default.ensureDirSync(cacheDir());
196
+ fs_extra_1.default.writeFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), JSON.stringify(trimmed));
197
+ }
198
+ catch {
199
+ // the cache is a convenience; probing again next time is fine
200
+ }
201
+ }
202
+ /**
203
+ * Which HBC version this hermesc emits. The answer is remembered per binary
204
+ * (path, size, mtime) in the cache dir so only the first run of a given
205
+ * hermesc pays for the empty-file compile.
206
+ */
167
207
  function probeHbcVersion(hermesCommand) {
208
+ const key = probeCacheKey(hermesCommand);
209
+ if (key) {
210
+ const cached = readProbeCache()[key];
211
+ if (Number.isInteger(cached) && cached > 0)
212
+ return cached;
213
+ }
214
+ const version = compileProbe(hermesCommand);
215
+ if (key && version !== null) {
216
+ const { [key]: _stale, ...others } = readProbeCache();
217
+ writeProbeCache({ ...others, [key]: version });
218
+ }
219
+ return version;
220
+ }
221
+ /** Compile an empty file to learn which HBC version this hermesc emits. */
222
+ function compileProbe(hermesCommand) {
168
223
  const dir = fs_extra_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-hermes-probe-'));
169
224
  try {
170
225
  const input = path_1.default.join(dir, 'probe.js');
@@ -198,6 +253,17 @@ exports.BUNDLE_ENTRY_NAMES = [
198
253
  ];
199
254
  const APK_BUNDLE = /^assets\/index\.android\.bundle$/;
200
255
  const IPA_BUNDLE = /^payload\/[^/]+\.app\/main\.jsbundle$/i;
256
+ /** Which zip entry holds the JS/HBC bundle in each kind of artifact. */
257
+ function bundleEntryMatcher(artifactType) {
258
+ switch (artifactType) {
259
+ case 'apk':
260
+ return (name) => APK_BUNDLE.test(name);
261
+ case 'ipa':
262
+ return (name) => IPA_BUNDLE.test(name.toLowerCase());
263
+ default:
264
+ return (name) => exports.BUNDLE_ENTRY_NAMES.includes(name);
265
+ }
266
+ }
201
267
  /**
202
268
  * Extract the JS/HBC bundle from a local artifact: a raw bundle file, a ppk,
203
269
  * or a native package (apk / ipa / harmony app). Returns null when not found.
@@ -211,14 +277,8 @@ async function extractBundleFromArchive(filePath) {
211
277
  ext === '.js') {
212
278
  return fs_extra_1.default.readFile(filePath);
213
279
  }
214
- if (ext === '.ppk') {
215
- return readFirstZipEntry(filePath, (name) => exports.BUNDLE_ENTRY_NAMES.includes(name));
216
- }
217
- if (ext === '.apk') {
218
- return readFirstZipEntry(filePath, (name) => APK_BUNDLE.test(name));
219
- }
220
- if (ext === '.ipa') {
221
- return readFirstZipEntry(filePath, (name) => IPA_BUNDLE.test(name.toLowerCase()));
280
+ if (ext === '.ppk' || ext === '.apk' || ext === '.ipa') {
281
+ return readFirstZipEntry(filePath, bundleEntryMatcher(ext.slice(1)));
222
282
  }
223
283
  if (ext === '.app') {
224
284
  // harmony .app wraps .hap archives; reuse the existing parser
@@ -280,8 +340,8 @@ async function cacheLookup(bundleHash) {
280
340
  return file;
281
341
  }
282
342
  /** Store a bundle under its sha256 (LRU-evicting to the configured limits). */
283
- async function cachePut(bundle, maxMb) {
284
- const bundleHash = sha256Hex(bundle);
343
+ async function cachePut(bundle, maxMb, knownHash) {
344
+ const bundleHash = knownHash ?? sha256Hex(bundle);
285
345
  const dir = cacheDir();
286
346
  await fs_extra_1.default.ensureDir(dir);
287
347
  const file = path_1.default.join(dir, bundleHash);
@@ -372,6 +432,106 @@ async function downloadToFile(url, destination) {
372
432
  const { Readable } = await Promise.resolve().then(() => __importStar(require('stream')));
373
433
  await (0, promises_1.pipeline)(Readable.fromWeb(response.body), fs_extra_1.default.createWriteStream(destination));
374
434
  }
435
+ function hasBundleLocation(record) {
436
+ return (record.bundleOffset != null &&
437
+ record.bundleCompressedSize != null &&
438
+ record.bundleCompression != null &&
439
+ (record.bundleCompression === zip_range_1.ZIP_STORED ||
440
+ record.bundleCompression === zip_range_1.ZIP_DEFLATED));
441
+ }
442
+ async function saveResponse(response, destination) {
443
+ if (!response.body)
444
+ throw new Error('empty response body');
445
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(destination));
446
+ const { Readable } = await Promise.resolve().then(() => __importStar(require('stream')));
447
+ await (0, promises_1.pipeline)(Readable.fromWeb(response.body), fs_extra_1.default.createWriteStream(destination));
448
+ }
449
+ /**
450
+ * Obtain the base bundle with as little traffic as possible, in order:
451
+ * 1. one Range request for the bundle's compressed bytes when the server
452
+ * knows their location (ppk / apk / ipa published by a CLI that
453
+ * reported it);
454
+ * 2. the archive's central directory over Range, then just the bundle
455
+ * entry (any zip: ppk, apk, ipa — harmony .app nests a second zip and
456
+ * is skipped);
457
+ * 3. the whole archive, as before.
458
+ * A server that ignores Range (HTTP 200) streams the full archive into
459
+ * `archive` without a second request. Range results are verified against
460
+ * `record.bundleHash` here; a mismatch (e.g. re-packaged object) falls
461
+ * through to the next transport instead of failing the resolution.
462
+ */
463
+ async function fetchBaseBundle(record, artifactType, archive, log = () => { }) {
464
+ const matches = bundleEntryMatcher(artifactType);
465
+ const verified = (bundle) => {
466
+ if (!bundle)
467
+ throw new Error('bundle entry not found');
468
+ const bundleHash = sha256Hex(bundle);
469
+ if (record.bundleHash && bundleHash !== record.bundleHash) {
470
+ throw new Error('bundleHash mismatch');
471
+ }
472
+ return { bundle, bundleHash };
473
+ };
474
+ const fromFullResponse = async (response) => {
475
+ await saveResponse(response, archive);
476
+ const bundle = await extractBundleFromArchive(archive);
477
+ return bundle
478
+ ? { bundle, bundleHash: sha256Hex(bundle), transport: 'full' }
479
+ : null;
480
+ };
481
+ const skip = (reason) => log((0, i18n_1.t)('hermesBaseRangeFallback', { reason }));
482
+ // harmony .app nests the bundle in a second zip, so a location inside the
483
+ // outer archive is never reported for it
484
+ if (artifactType !== 'app' && hasBundleLocation(record)) {
485
+ try {
486
+ const { data, fetchedBytes, totalBytes } = await (0, zip_range_1.fetchZipEntryData)(record.url, {
487
+ dataOffset: record.bundleOffset,
488
+ compressedSize: record.bundleCompressedSize,
489
+ compressionMethod: record.bundleCompression,
490
+ });
491
+ return {
492
+ ...verified(data),
493
+ transport: 'range-entry',
494
+ fetchedBytes,
495
+ totalBytes,
496
+ };
497
+ }
498
+ catch (error) {
499
+ if (error instanceof zip_range_1.RangeUnsupportedError) {
500
+ skip('server ignores Range');
501
+ return fromFullResponse(error.response);
502
+ }
503
+ skip(`entry range: ${error?.message ?? error}`);
504
+ }
505
+ }
506
+ if (artifactType !== 'app') {
507
+ try {
508
+ const remote = await (0, zip_range_1.openRemoteZip)(record.url);
509
+ if (remote.kind === 'full') {
510
+ skip('server ignores Range');
511
+ return fromFullResponse(remote.response);
512
+ }
513
+ const bundle = await (0, zip_range_1.readRemoteZipEntry)(remote.zipFile, matches, remote.reader);
514
+ return {
515
+ ...verified(bundle),
516
+ transport: 'range-zip',
517
+ fetchedBytes: remote.reader.fetchedBytes,
518
+ totalBytes: remote.reader.totalSize,
519
+ };
520
+ }
521
+ catch (error) {
522
+ if (error instanceof zip_range_1.RangeUnsupportedError) {
523
+ skip('server ignores Range');
524
+ return fromFullResponse(error.response);
525
+ }
526
+ skip(`zip range: ${error?.message ?? error}`);
527
+ }
528
+ }
529
+ await downloadToFile(record.url, archive);
530
+ const bundle = await extractBundleFromArchive(archive);
531
+ return bundle
532
+ ? { bundle, bundleHash: sha256Hex(bundle), transport: 'full' }
533
+ : null;
534
+ }
375
535
  /**
376
536
  * Pick and materialize the base bundle for this compile. Returns null (with
377
537
  * the reason logged) whenever a base cannot be used; callers then compile
@@ -462,17 +622,27 @@ async function resolveHermesBase(params) {
462
622
  for (let attempt = 1; attempt <= 2; attempt++) {
463
623
  const dir = tmpDir();
464
624
  await fs_extra_1.default.ensureDir(dir);
465
- const artifactType = ['ppk', 'apk', 'ipa', 'app'].includes(record.artifactType ?? '')
625
+ const artifactType = [
626
+ 'ppk',
627
+ 'apk',
628
+ 'ipa',
629
+ 'app',
630
+ ].includes(record.artifactType ?? '')
466
631
  ? record.artifactType
467
632
  : 'ppk';
468
633
  const archive = path_1.default.join(dir, `base-${process.pid}-${Date.now()}-${attempt}.${artifactType}`);
469
634
  try {
470
635
  log((0, i18n_1.t)('hermesBaseDownloading', { url: record.url }));
471
- await downloadToFile(record.url, archive);
472
- const bundle = await extractBundleFromArchive(archive);
473
- if (!bundle)
636
+ const fetched = await fetchBaseBundle(record, artifactType, archive, log);
637
+ if (!fetched)
474
638
  throw new Error('bundle entry not found in downloaded package');
475
- const actualHash = sha256Hex(bundle);
639
+ const { bundle, bundleHash: actualHash } = fetched;
640
+ if (fetched.transport !== 'full') {
641
+ log((0, i18n_1.t)('hermesBaseRangeFetched', {
642
+ fetchedKb: Math.ceil((fetched.fetchedBytes ?? 0) / 1024),
643
+ totalKb: Math.ceil((fetched.totalBytes ?? 0) / 1024),
644
+ }));
645
+ }
476
646
  if (record.bundleHash && actualHash !== record.bundleHash) {
477
647
  throw new Error(`bundleHash mismatch (${actualHash.slice(0, 12)} != ${record.bundleHash.slice(0, 12)})`);
478
648
  }
@@ -483,7 +653,7 @@ async function resolveHermesBase(params) {
483
653
  }));
484
654
  return null;
485
655
  }
486
- const cached = await cachePut(bundle, params.cacheMaxMb);
656
+ const cached = await cachePut(bundle, params.cacheMaxMb, actualHash);
487
657
  log((0, i18n_1.t)('hermesBaseUsing', {
488
658
  source: record.versionId == null
489
659
  ? `native package ${record.hash.slice(0, 8)}`
@@ -534,44 +704,84 @@ const STRING_TABLE_LINE = /^\s*[is](\d+)\[[^\]]*\](?: #[0-9A-F]+)?: (.*)$/;
534
704
  * distances follow instruction widths. Everything else must match exactly.
535
705
  */
536
706
  function normalizeDisassemblyLine(line, strings) {
537
- if (/^Offset in debug table/.test(line))
707
+ // Cheap dispatch on the opcode before touching any regex: dumps run to
708
+ // millions of lines and only a handful of instructions need rewriting.
709
+ let indent = 0;
710
+ while (indent < line.length && isSpace(line.charCodeAt(indent)))
711
+ indent++;
712
+ let opEnd = indent;
713
+ while (opEnd < line.length && isLetter(line.charCodeAt(opEnd)))
714
+ opEnd++;
715
+ const opcode = line.slice(indent, opEnd);
716
+ if (opcode === 'Offset' && line.startsWith('Offset in debug table', indent)) {
538
717
  return null;
539
- let m = /^(\s*New(?:Array|Object)WithBuffer)(?:Long)?(?:AndParent)?\s+(r\d+)(.*)$/.exec(line);
540
- if (m) {
541
- const nums = m[3].match(/\d+/g) ?? [];
542
- return `${m[1]} ${m[2]} sizes=${nums.slice(0, 1).join(',')}`;
543
- }
544
- m = /^(\s*J[A-Za-z]+?)(Long)?\s+(L\d+|\d+)(.*)$/.exec(line);
545
- if (m)
546
- return `${m[1]} <tgt>${m[4]}`;
547
- m = /^(\s*DefineOwnById\w*\s+r\d+, r\d+, \d+, )(\d+)$/.exec(line);
548
- if (m)
549
- line = `${m[1]}"${strings.get(Number(m[2])) ?? `?${m[2]}`}"`;
718
+ }
719
+ let m;
720
+ if (opcode.startsWith('New') && opcode.includes('WithBuffer')) {
721
+ m =
722
+ /^(\s*New(?:Array|Object)WithBuffer)(?:Long)?(?:AndParent)?\s+(r\d+)(.*)$/.exec(line);
723
+ if (m) {
724
+ const nums = m[3].match(/\d+/g) ?? [];
725
+ return `${m[1]} ${m[2]} sizes=${nums.slice(0, 1).join(',')}`;
726
+ }
727
+ }
728
+ if (opcode.charCodeAt(0) === 0x4a /* J */) {
729
+ m = /^(\s*J[A-Za-z]+?)(Long)?\s+(L\d+|\d+)(.*)$/.exec(line);
730
+ if (m)
731
+ return `${m[1]} <tgt>${m[4]}`;
732
+ }
733
+ if (opcode.startsWith('DefineOwnById')) {
734
+ m = /^(\s*DefineOwnById\w*\s+r\d+, r\d+, \d+, )(\d+)$/.exec(line);
735
+ if (m)
736
+ line = `${m[1]}"${strings.get(Number(m[2])) ?? `?${m[2]}`}"`;
737
+ }
550
738
  // Operand-width variants of one instruction (GetByIdShort/GetById/GetByIdLong,
551
739
  // LoadConstString/LoadConstStringLongIndex, ...) only differ by how wide a
552
740
  // string/function id or offset is encoded — a foreign base hands the new
553
741
  // code's hot strings large ids, so the delta build legitimately picks the
554
742
  // wider form. Fold the suffix and the column padding that follows it.
555
- m = /^(\s*)([A-Za-z]+?)(?:LongIndex|Long|Short)?(\s+.*|)$/.exec(line);
556
- if (m)
557
- line = `${m[1]}${m[2]}${m[3].replace(/\s+/g, ' ')}`;
558
- // Switch jump tables sit after the instructions; their relative offset (and
559
- // the table header hermesc prints for them) moves with instruction widths.
560
- // The two switch instructions carry that offset in different operands:
561
- // StringSwitchImm rX, <id>, <jtOffset>, <defaultLabel>, <count>
562
- // UIntSwitchImm rX, <jtOffset>, <defaultLabel>, <min>, <max>
563
- // Folding only the first shape let a shifted UIntSwitchImm offset read as a
564
- // real difference and drop an otherwise good delta build.
565
- m = /^(\s*StringSwitchImm r\d+, \d+, )\d+(, L\d+, \d+)$/.exec(line);
566
- if (m)
567
- line = `${m[1]}<jt>${m[2]}`;
568
- m = /^(\s*UIntSwitchImm r\d+, )\d+(, L\d+, \d+, \d+)$/.exec(line);
569
- if (m)
570
- line = `${m[1]}<jt>${m[2]}`;
571
- if (/^\s*offset \d+$/.test(line))
572
- line = line.replace(/\d+$/, '<jt>');
743
+ if (opEnd > indent &&
744
+ (opEnd === line.length || isSpace(line.charCodeAt(opEnd)))) {
745
+ const folded = foldWidthSuffix(opcode);
746
+ line = `${line.slice(0, indent)}${folded}${line.slice(opEnd).replace(/\s+/g, ' ')}`;
747
+ // Switch jump tables sit after the instructions; their relative offset (and
748
+ // the table header hermesc prints for them) moves with instruction widths.
749
+ // The two switch instructions carry that offset in different operands:
750
+ // StringSwitchImm rX, <id>, <jtOffset>, <defaultLabel>, <count>
751
+ // UIntSwitchImm rX, <jtOffset>, <defaultLabel>, <min>, <max>
752
+ // Folding only the first shape let a shifted UIntSwitchImm offset read as a
753
+ // real difference and drop an otherwise good delta build.
754
+ if (folded === 'StringSwitchImm') {
755
+ m = /^(\s*StringSwitchImm r\d+, \d+, )\d+(, L\d+, \d+)$/.exec(line);
756
+ if (m)
757
+ line = `${m[1]}<jt>${m[2]}`;
758
+ }
759
+ else if (folded === 'UIntSwitchImm') {
760
+ m = /^(\s*UIntSwitchImm r\d+, )\d+(, L\d+, \d+, \d+)$/.exec(line);
761
+ if (m)
762
+ line = `${m[1]}<jt>${m[2]}`;
763
+ }
764
+ else if (folded === 'offset' && /^\s*offset \d+$/.test(line)) {
765
+ line = line.replace(/\d+$/, '<jt>');
766
+ }
767
+ }
573
768
  return line;
574
769
  }
770
+ function isSpace(code) {
771
+ return code === 0x20 || code === 0x09 || code === 0x0d;
772
+ }
773
+ function isLetter(code) {
774
+ return (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a);
775
+ }
776
+ /** strip one operand-width suffix (LongIndex, Long, Short) off an opcode */
777
+ function foldWidthSuffix(opcode) {
778
+ for (const suffix of ['LongIndex', 'Long', 'Short']) {
779
+ if (opcode.length > suffix.length && opcode.endsWith(suffix)) {
780
+ return opcode.slice(0, -suffix.length);
781
+ }
782
+ }
783
+ return opcode;
784
+ }
575
785
  /** Split a readable stream into lines without readline (Bun's readline async iterator misbehaves when pulled manually). */
576
786
  async function* streamLines(stream) {
577
787
  let rest = '';
@@ -0,0 +1,111 @@
1
+ import { Readable } from 'stream';
2
+ import { type Entry, RandomAccessReader, type ZipFile } from 'yauzl';
3
+ export declare const ZIP_STORED = 0;
4
+ export declare const ZIP_DEFLATED = 8;
5
+ export interface ZipEntryLocation {
6
+ fileName: string;
7
+ /** absolute offset of the compressed data, past the local file header */
8
+ dataOffset: number;
9
+ compressedSize: number;
10
+ uncompressedSize: number;
11
+ /** 0 = stored, 8 = deflate; anything else cannot be inflated here */
12
+ compressionMethod: number;
13
+ }
14
+ /** Data location of the first entry matching `matches` in a local zip. */
15
+ export declare function locateZipEntry(zipPath: string, matches: (name: string) => boolean): Promise<ZipEntryLocation | null>;
16
+ /**
17
+ * Content and data location of the first matching entry in one pass over the
18
+ * archive (publish needs both: the bundle to hash and cache, its location to
19
+ * report to the server).
20
+ */
21
+ export declare function readZipEntryWithLocation(zipPath: string, matches: (name: string) => boolean): Promise<{
22
+ data: Buffer;
23
+ location: ZipEntryLocation;
24
+ } | null>;
25
+ /**
26
+ * The `bundleOffset` / `bundleCompressedSize` / `bundleCompression` fields for
27
+ * version/create and package/create, or nothing when the entry cannot be
28
+ * fetched by a single Range request (unknown, empty or exotic compression).
29
+ */
30
+ export declare function bundleLocationFields(location: ZipEntryLocation | null | undefined): Record<string, number>;
31
+ /** The server answered a Range request with the whole body (HTTP 200). */
32
+ export declare class RangeUnsupportedError extends Error {
33
+ readonly response: Response;
34
+ constructor(response: Response);
35
+ }
36
+ interface ContentRange {
37
+ start: number;
38
+ end: number;
39
+ total: number;
40
+ }
41
+ export declare function parseContentRange(header: string | null): ContentRange | null;
42
+ /**
43
+ * Fetch one entry whose compressed bytes are already located (the ppk's own
44
+ * publish-time report) and decompress it. Returns the raw entry content.
45
+ */
46
+ export declare function fetchZipEntryData(url: string, location: Pick<ZipEntryLocation, 'dataOffset' | 'compressedSize' | 'compressionMethod'>): Promise<{
47
+ data: Buffer;
48
+ fetchedBytes: number;
49
+ totalBytes: number;
50
+ }>;
51
+ /**
52
+ * yauzl reader over HTTP Range. Header reads (EOCD, central directory, local
53
+ * file headers) are widened to CHUNK_BYTES and cached — adjacent or
54
+ * overlapping chunks are merged so a read never re-fetches bytes it already
55
+ * has — and entry data reuses whatever prefix the cache holds (typically the
56
+ * bytes following the local file header) before requesting the rest.
57
+ */
58
+ export declare class HttpRangeReader extends RandomAccessReader {
59
+ private readonly url;
60
+ readonly totalSize: number;
61
+ private chunks;
62
+ /** span a header read inside it should widen to (see `hintEntry`) */
63
+ private hint;
64
+ requests: number;
65
+ fetchedBytes: number;
66
+ constructor(url: string, totalSize: number, tail?: {
67
+ start: number;
68
+ data: Buffer;
69
+ });
70
+ /**
71
+ * The next entry to be read: yauzl first reads its local file header, and
72
+ * widening that read to the entry's data makes the data stream a cache hit
73
+ * — one request for header + bundle instead of two. The central directory
74
+ * may understate the local header's extra field, hence the slack.
75
+ */
76
+ hintEntry(entry: Entry): void;
77
+ /** Cache `data` at `start`, merging with any chunk it touches. */
78
+ addChunk(start: number, data: Buffer): void;
79
+ /** cached bytes starting exactly at `start`, up to `end` (may be shorter) */
80
+ private cachedPrefix;
81
+ private cached;
82
+ /** start of the cached chunk holding byte `end - 1`, when there is one */
83
+ private cachedSuffixStart;
84
+ _readStreamForRange(start: number, end: number): Readable;
85
+ read(buffer: Buffer, offset: number, length: number, position: number, callback: (err: Error | null, bytesRead?: number) => void): void;
86
+ }
87
+ export declare function parseEndOfCentralDirectory(tail: Buffer): {
88
+ cdOffset: number;
89
+ cdSize: number;
90
+ } | null;
91
+ export type RemoteZip = {
92
+ kind: 'zip';
93
+ zipFile: ZipFile;
94
+ reader: HttpRangeReader;
95
+ }
96
+ /** the server ignored Range: the whole archive is streaming in `response` */
97
+ | {
98
+ kind: 'full';
99
+ response: Response;
100
+ };
101
+ /**
102
+ * Open a remote zip by fetching its tail (EOCD + central directory for
103
+ * typical archives) and letting yauzl read the rest on demand.
104
+ */
105
+ export declare function openRemoteZip(url: string): Promise<RemoteZip>;
106
+ /**
107
+ * Read the first matching entry of an opened remote zip, then close it. With
108
+ * `reader` given, the entry's header and data are fetched in one request.
109
+ */
110
+ export declare function readRemoteZipEntry(zipFile: ZipFile, matches: (name: string) => boolean, reader?: HttpRangeReader): Promise<Buffer | null>;
111
+ export {};