MCPcopy Create free account
hub / github.com/Effect-TS/effect / readCurrent

Method readCurrent

packages/effect/src/encoding/Zip.ts:1339–1388  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1337 }
1338
1339 private readCurrent(): Arr.NonEmptyArray<Uint8Array> | undefined | typeof NeedInput {
1340 const current = this.current
1341 if (current === undefined) return undefined
1342 const queue = this.queue
1343 if (!current.dataDone) {
1344 if (current.inflater === undefined) {
1345 if (current.remaining > 0) {
1346 if (queue.length === 0) return this.needInput()
1347 const chunks: Array<Uint8Array> = []
1348 while (current.remaining > 0 && queue.length > 0) {
1349 const chunk = queue.takeSome(current.remaining)
1350 current.remaining -= chunk.length
1351 current.actualCrc = crc32(current.actualCrc, chunk)
1352 current.actualSize += chunk.length
1353 chunks.push(chunk)
1354 }
1355 current.actualCompressedSize = current.actualSize
1356 return chunks as Arr.NonEmptyArray<Uint8Array>
1357 }
1358 } else {
1359 let chunk: Uint8Array | undefined | typeof NeedInput
1360 try {
1361 chunk = current.inflater.pull()
1362 } catch (error) {
1363 throw error instanceof InflateError ? invalidData(error.message) : error
1364 }
1365 if (chunk === NeedInput) return this.needInput()
1366 if (chunk !== undefined) {
1367 current.actualSize += chunk.length
1368 // Fail before handing out bytes past the reported size, so that
1369 // consumers can limit what a small compressed entry inflates to
1370 const { path, size } = current.header
1371 if (size !== undefined && current.actualSize > size) throw sizeMismatch(path, current.actualSize, size)
1372 current.actualCrc = crc32(current.actualCrc, chunk)
1373 return [chunk]
1374 }
1375 current.actualCompressedSize = queue.consumed - current.start
1376 }
1377 current.dataDone = true
1378 }
1379 if (current.descriptor) {
1380 const descriptor = this.descriptor(current)
1381 if (descriptor === NeedInput) return NeedInput
1382 this.check(current, descriptor.crc, descriptor.compressedSize, descriptor.size)
1383 } else {
1384 this.check(current, current.crc, current.compressedSize!, current.size!)
1385 }
1386 this.current = undefined
1387 return undefined
1388 }
1389
1390 private check(current: Current, crc: number, compressedSize: number, size: number): void {
1391 if (current.actualCrc === crc && current.actualCompressedSize === compressedSize && current.actualSize === size) {

Callers 2

advanceMethod · 0.95
readMethod · 0.95

Calls 9

needInputMethod · 0.95
descriptorMethod · 0.95
checkMethod · 0.95
invalidDataFunction · 0.85
crc32Function · 0.70
sizeMismatchFunction · 0.70
pushMethod · 0.65
takeSomeMethod · 0.45
pullMethod · 0.45

Tested by

no test coverage detected