MCPcopy Create free account
hub / github.com/denoland/std / #parseHeaderInto

Method #parseHeaderInto

tar/tar_stream.ts:253–345  ·  view source on GitHub ↗
(
    input: TarStreamInput,
    buffer: Uint8Array_,
  )

Source from the content-addressed store, hash-verified

251 }
252
253 #parseHeaderInto(
254 input: TarStreamInput,
255 buffer: Uint8Array_,
256 ): void {
257 input.options ??= {};
258 input.options.mode ??= input.type === "file"
259 ? 0o644
260 : input.type === "symlink"
261 ? 0o777
262 : 0o755;
263 input.options.uid ??= 0o0;
264 input.options.gid ??= 0o0;
265 input.options.mtime ??= Math.floor(Date.now() / 1000);
266 input.options.uname ??= "";
267 input.options.gname ??= "";
268 input.options.devmajor ??= "";
269 input.options.devminor ??= "";
270 assertValidTarStreamOptions(input.options);
271 if (
272 input.type === "file" &&
273 (input.size < 0 || 8 ** 12 < input.size || Number.isNaN(input.size))
274 ) {
275 throw new RangeError(
276 "Cannot add to the tar archive: The size cannot exceed 64 Gibs",
277 );
278 }
279
280 // name (100) & prefix (155)
281 this.#parsePathInto(input.path, buffer);
282 // mode (8)
283 parseOctalInto(input.options.mode, buffer.subarray(100, 106));
284 buffer[106] = 32;
285 buffer[107] = 0;
286 // uid (8)
287 parseOctalInto(input.options.uid, buffer.subarray(108, 114));
288 buffer[114] = 32;
289 buffer[115] = 0;
290 // gid (8)
291 parseOctalInto(input.options.gid, buffer.subarray(116, 122));
292 buffer[122] = 32;
293 buffer[123] = 0;
294 // size (12)
295 const size = input.type === "file" ? input.size : 0;
296 buffer[135] = 32;
297 parseOctalInto(size, buffer.subarray(124, 135 + +(8 ** 11 < size)));
298 // mtime (12)
299 parseOctalInto(input.options.mtime, buffer.subarray(136, 147));
300 buffer[147] = 32;
301 // checksum (8)
302 buffer.fill(32, 148, 156);
303 // typeflag (1)
304 buffer[156] = input.type === "file"
305 ? 48
306 : input.type === "symlink"
307 ? 50
308 : 53;
309 // linkname (100)
310 buffer.fill(0, 157, 257);

Callers 1

#tarMethod · 0.95

Calls 6

#parsePathIntoMethod · 0.95
parseOctalIntoFunction · 0.85
checkLinknameFunction · 0.85
floorMethod · 0.80
nowMethod · 0.80

Tested by

no test coverage detected