MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / _readEntry

Method _readEntry

packages/alphatab/src/zip/ZipReader.ts:31–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29 }
30
31 private _readEntry(): ZipEntry | null {
32 const readable: IReadable = this._readable;
33 const h: number = IOHelper.readInt32LE(readable);
34 if (h !== ZipEntry.LocalFileHeaderSignature) {
35 return null;
36 }
37 // 4.3.7 local file header
38 IOHelper.readUInt16LE(readable); // version
39
40 const flags: number = IOHelper.readUInt16LE(readable);
41 const compressionMethod: number = IOHelper.readUInt16LE(readable);
42 const compressed: boolean = compressionMethod !== 0;
43 if (compressed && compressionMethod !== ZipEntry.CompressionMethodDeflate) {
44 return null;
45 }
46
47 IOHelper.readInt16LE(this._readable); // last mod file time
48 IOHelper.readInt16LE(this._readable); // last mod file date
49 IOHelper.readInt32LE(readable); // crc-32
50 IOHelper.readInt32LE(readable); // compressed size
51
52 const uncompressedSize: number = IOHelper.readInt32LE(readable);
53 if (uncompressedSize > this._maxDecodingBufferSize) {
54 throw new OverflowError(`Zip contains files exceeding the configured maxDecodingBufferSize`);
55 }
56 const fileNameLength: number = IOHelper.readInt16LE(readable);
57 if (fileNameLength > this._maxDecodingBufferSize) {
58 throw new OverflowError(`Zip contains file names exceeding the configured maxDecodingBufferSize`);
59 }
60
61 const extraFieldLength: number = IOHelper.readInt16LE(readable);
62
63 const fname: string = IOHelper.toString(IOHelper.readByteArray(readable, fileNameLength), 'utf-8');
64 readable.skip(extraFieldLength);
65
66 // 4.3.8 File Data
67 let data: Uint8Array;
68 if (compressed) {
69 const target: ByteBuffer = ByteBuffer.empty();
70 const z: Inflate = new Inflate(this._readable);
71 const buffer: Uint8Array = new Uint8Array(65536);
72 while (true) {
73 const bytes: number = z.readBytes(buffer, 0, buffer.length);
74 target.write(buffer, 0, bytes);
75 if (target.length > this._maxDecodingBufferSize) {
76 throw new OverflowError(
77 `Zip entry "${fname}" contains data exceeding the configured maxDecodingBufferSize`
78 );
79 }
80 if (bytes < buffer.length) {
81 break;
82 }
83 }
84 data = target.toArray();
85 } else {
86 data = IOHelper.readByteArray(this._readable, uncompressedSize);
87 }
88

Callers 1

readMethod · 0.95

Calls 10

readBytesMethod · 0.95
readInt32LEMethod · 0.80
readUInt16LEMethod · 0.80
readInt16LEMethod · 0.80
readByteArrayMethod · 0.80
emptyMethod · 0.80
toArrayMethod · 0.80
skipMethod · 0.65
writeMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected