browser-stream-tar
v3.0.3
Published
split tar web-stream into a sequence of Files
Downloads
571
Readme
browser-stream-tar
split tar web-stream into a sequence of Files
example
import { files } from "browser-stream-tar";
const response = await fetch("some tar file");
for await (const file of files(response.body)) {
console.log(file.name);
// do something with entry.stream()
}
API
Table of Contents
- BLOCKSIZE
- decodePaxHeader
- decodeHeader
- files
- enqueue
- buffer
- decodeString
- decodeInteger
- fill
- skip
- streamToUint8Array
BLOCKSIZE
Field Name Byte Offset Length in Bytes Field Type name 0 100 NUL-terminated if NUL fits mode 100 8 uid 108 8 gid 116 8 size 124 12 mtime 136 12 chksum 148 8 typeflag 156 1 see below linkname 157 100 NUL-terminated if NUL fits magic 257 6 must be TMAGIC (NUL term.) version 263 2 must be TVERSION uname 265 32 NUL-terminated gname 297 32 NUL-terminated devmajor 329 8 devminor 337 8 prefix 345 155 NUL-terminated if NUL fits
Type: number
decodePaxHeader
Decodes a PAX header
Parameters
reader
ReadableStreamReader where to read frombuffer
Uint8Arrayheader
Object to be filled with values form buffer
Returns Promise<Uint8Array> buffer positioned after the consumed bytes
decodeHeader
Decodes the next header.
Parameters
reader
ReadableStreamReader<Uint8Array> where to read frombuffer
(Uint8Array | undefined)header
Object to be filled with values form buffer and reader
Returns Promise<(Uint8Array | undefined)> buffer positioned after the consumed bytes
files
Provide tar entry iterator.
Parameters
tar
ReadableStream
Returns AsyncIterable<File>
enqueue
--512--|-----512------| | R | O | | DDDDDDDDDDDD---------HHHH | | | A0 A0 A1
buffer
+--------- size --------+ | +- remaining -+- overflow -+ | | | | HDD ... DDDDDDDDDDDDDDDDDD------------HHHHHH [BUFFER .... ] [BUFFER ... ] +----------- skip --------+
decodeString
Convert bytes into string.
Parameters
bytes
Uint8Array
Returns string
decodeInteger
Convert ASCII octal number into number.
Parameters
bytes
Uint8Array
Returns number
fill
Read bytes from a reader and append them to a given buffer until a requested length of the buffer is reached.
Parameters
reader
ReadableStreamReader<Uint8Array> where to read frombuffer
Uint8Array? initial buffer or undefinedlength
number? desired buffer length
Returns Promise<(Uint8Array | undefined)> filled up buffer
skip
Skip some bytes from a buffer.
Parameters
reader
ReadableStreamReader<Uint8Array> where to read frombuffer
Uint8Arraylength
number to be skipped
Returns Promise<(Uint8Array | undefined)> buffer positionend after skipped bytes
streamToUint8Array
Reads web stream content into a Uint8Array.
Parameters
stream
ReadableStream
Returns Promise<Uint8Array>
install
With npm do:
npm install browser-stream-tar
license
BSD-2-Clause