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

Function centralHeader

packages/effect/src/encoding/Zip.ts:1003–1038  ·  view source on GitHub ↗
(record: EntryRecord)

Source from the content-addressed store, hash-verified

1001}
1002
1003const centralHeader = (record: EntryRecord): Uint8Array => {
1004 // ZIP64 holds only the fields that overflow, in this order
1005 const wide: Array<number> = []
1006 if (record.size >= MAX32) wide.push(record.size)
1007 if (record.compressedSize >= MAX32) wide.push(record.compressedSize)
1008 if (record.offset >= MAX32) wide.push(record.offset)
1009 const zip64Length = wide.length === 0 ? 0 : 4 + 8 * wide.length
1010 const extraLength = zip64Length + timestampLength(record)
1011 const version = wide.length === 0 && !record.zip64 ? VERSION : VERSION_ZIP64
1012 const bytes = new Uint8Array(46 + record.name.length + extraLength)
1013 const view = new DataView(bytes.buffer)
1014 view.setUint32(0, CENTRAL, true)
1015 view.setUint16(4, (CREATOR_UNIX << 8) | version, true)
1016 view.setUint16(6, version, true)
1017 view.setUint16(8, record.flags, true)
1018 view.setUint16(10, record.method, true)
1019 view.setUint16(12, record.time, true)
1020 view.setUint16(14, record.date, true)
1021 view.setUint32(16, record.crc, true)
1022 view.setUint32(20, Math.min(record.compressedSize, MAX32), true)
1023 view.setUint32(24, Math.min(record.size, MAX32), true)
1024 view.setUint16(28, record.name.length, true)
1025 view.setUint16(30, extraLength, true)
1026 view.setUint32(38, record.external, true)
1027 view.setUint32(42, Math.min(record.offset, MAX32), true)
1028 bytes.set(record.name, 46)
1029 let at = 46 + record.name.length
1030 if (wide.length > 0) {
1031 view.setUint16(at, EXTRA_ZIP64, true)
1032 view.setUint16(at + 2, 8 * wide.length, true)
1033 for (let i = 0; i < wide.length; i++) setUint64(view, at + 4 + 8 * i, wide[i])
1034 at += zip64Length
1035 }
1036 writeTimestamp(bytes, view, at, record)
1037 return bytes
1038}
1039
1040const SLAB_SIZE = 64 * 1024
1041

Callers 1

finishMethod · 0.85

Calls 5

timestampLengthFunction · 0.85
setUint64Function · 0.85
writeTimestampFunction · 0.85
pushMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected