| 1095 | } |
| 1096 | |
| 1097 | private record(header: Header, flags: number): EntryRecord { |
| 1098 | const name = textEncoder.encode(header.path) |
| 1099 | if (name.length > MAX16) throw invalidHeader(`path ${JSON.stringify(header.path)} is longer than 65535 bytes`) |
| 1100 | const { date, time } = toDos(header.mtime) |
| 1101 | const seconds = Math.floor(header.mtime.getTime() / 1000) |
| 1102 | const directory = header.type === "Directory" |
| 1103 | const mode = header.mode ?? (directory ? 0o755 : 0o644) |
| 1104 | return { |
| 1105 | name, |
| 1106 | // The UTF-8 byte length equals the string length only for ASCII |
| 1107 | flags: name.length === header.path.length ? flags : flags | FLAG_UTF8, |
| 1108 | method: header.type === "File" && header.method === "Deflate" ? 8 : 0, |
| 1109 | time, |
| 1110 | date, |
| 1111 | seconds: seconds >= 0 && seconds <= 0x7fffffff ? seconds : undefined, |
| 1112 | external: (((directory ? S_IFDIR : S_IFREG) | mode) * 0x10000 + (directory ? DOS_DIRECTORY : 0)) >>> 0, |
| 1113 | offset: this.offset, |
| 1114 | zip64: false, |
| 1115 | crc: 0, |
| 1116 | compressedSize: 0, |
| 1117 | size: 0 |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | // Writes an entry whose content is known, with its sizes in the local header |
| 1122 | entry(header: Header, content: Uint8Array, data: Uint8Array): void { |