@fuman/io 0.0.4 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/_utils.d.cts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function nextPowerOfTwo(n: number): number;
2
+ export declare function getDv(buffer: Uint8Array): DataView;
@@ -0,0 +1,2 @@
1
+ export * from './reader.js';
2
+ export * from './utils.js';
@@ -0,0 +1,20 @@
1
+ import { ISyncReadable } from '../types.js';
2
+ /** a bit reader that reads bits from a byte-aligned stream */
3
+ export declare class BitReader implements ISyncReadable {
4
+ #private;
5
+ /** @param readable fuman readable stream */
6
+ constructor(readable: ISyncReadable);
7
+ /** Whether the reader is currently aligned on a byte boundary */
8
+ get isAligned(): boolean;
9
+ /** Skip any remaining bits in the current byte. No-op if already aligned */
10
+ align(): void;
11
+ /** The current bit position within the last consumed byte */
12
+ get bitPosition(): number;
13
+ readSync(bytes: number): Uint8Array;
14
+ /** read a number of bits from the stream, and return them as a number */
15
+ readBits(size: number): number;
16
+ /** read a number of bits from the stream, and return them as a bigint */
17
+ readBitsBig(size: number): bigint;
18
+ /** skip a number of bits from the stream */
19
+ skipBits(size: number): void;
20
+ }
@@ -0,0 +1,12 @@
1
+ /** Reverse bit ordering of a single byte */
2
+ export declare function reverse8Bits(byte: number): number;
3
+ /** Reverse bits of a numeric value, treating it as a `size`-bit number */
4
+ export declare function reverseBits(value: number, size: number): number;
5
+ /** Reverse bits of a bigint, treating it as a `size`-bit number */
6
+ export declare function reverseBitsBig(value: bigint, size: number | bigint): bigint;
7
+ /**
8
+ * Reverse the bit ordering of each byte in the byte array, **in place**
9
+ *
10
+ * @example `reverseBitsAll(new Uint8Array([0b10101010, 0b01010101])) // becomes [0b01010101, 0b10101010]
11
+ */
12
+ export declare function reverseBitsAll(buf: Uint8Array): void;
@@ -0,0 +1,10 @@
1
+ import { IReadable } from './types.js';
2
+ export declare class BufReader implements IReadable {
3
+ #private;
4
+ constructor(readable: IReadable, size?: number);
5
+ /** the size of the buffer */
6
+ get bufferSize(): number;
7
+ /** the number of bytes that are currently buffered */
8
+ get buffered(): number;
9
+ read(into: Uint8Array): Promise<number>;
10
+ }
package/bytes.d.cts ADDED
@@ -0,0 +1,32 @@
1
+ import { IReadable, ISyncReadable, ISyncWritable, IWritable } from './types.js';
2
+ /** a byte buffer implementing fuman readable/writable streams */
3
+ export declare class Bytes implements IReadable, IWritable, ISyncReadable, ISyncWritable {
4
+ #private;
5
+ constructor(buf: Uint8Array);
6
+ static alloc(capacity?: number): Bytes;
7
+ static from(data: Uint8Array): Bytes;
8
+ /** Total number of bytes in the underlying buffer */
9
+ get capacity(): number;
10
+ /** Number of bytes available to be read */
11
+ get available(): number;
12
+ /** Number of bytes written */
13
+ get written(): number;
14
+ readSync(bytes: number): Uint8Array;
15
+ read(into: Uint8Array): Promise<number>;
16
+ writeSync(size: number): Uint8Array;
17
+ disposeWriteSync(written?: number): void;
18
+ write(bytes: Uint8Array): Promise<void>;
19
+ /**
20
+ * get the "result" of the buffer, i.e. everything that has been written so far,
21
+ * but not yet read
22
+ *
23
+ * **Note**: this method returns a view into the underlying buffer, and does advance the read cursor
24
+ */
25
+ result(): Uint8Array;
26
+ /** Reclaim memory by only keeping the yet-unread data */
27
+ reclaim(): void;
28
+ /** Mark last n bytes as unread */
29
+ rewind(n: number): void;
30
+ /** reset the read/write cursors */
31
+ reset(): void;
32
+ }
@@ -0,0 +1,30 @@
1
+ import { Bytes } from '../bytes.js';
2
+ import { ISyncWritable } from '../types.js';
3
+ import { IFrameDecoder, IFrameEncoder } from './types.js';
4
+ /** options for {@link DelimiterCodec} */
5
+ export interface DelimiterCodecOptions {
6
+ /**
7
+ * Strategy for handling delimiter.
8
+ * - `keep` - delimiter is kept at the end of each frame
9
+ * - `discard` - delimiter is discarded
10
+ *
11
+ * Ignored for encoding (delimiter is always appended after the frame)
12
+ *
13
+ * @default 'discard'
14
+ */
15
+ strategy?: 'keep' | 'discard';
16
+ }
17
+ /** a simple frame codec that uses a delimiter to separate frames */
18
+ export declare class DelimiterCodec implements IFrameDecoder, IFrameEncoder {
19
+ #private;
20
+ readonly delimiter: Uint8Array;
21
+ readonly options?: DelimiterCodecOptions | undefined;
22
+ /**
23
+ * @param delimiter delimiter to use
24
+ * @param options options
25
+ */
26
+ constructor(delimiter: Uint8Array, options?: DelimiterCodecOptions | undefined);
27
+ decode(buf: Bytes, eof: boolean): Uint8Array | null;
28
+ encode(data: Uint8Array, into: ISyncWritable): void;
29
+ reset(): void;
30
+ }
@@ -0,0 +1,6 @@
1
+ export * from './delimiter.js';
2
+ export * from './length-delimited.js';
3
+ export * from './reader.js';
4
+ export * from './text-delimiter.js';
5
+ export * from './types.js';
6
+ export * from './writer.js';
@@ -0,0 +1,26 @@
1
+ import { Bytes } from '../bytes.js';
2
+ import { ISyncWritable } from '../types.js';
3
+ import { IFrameDecoder, IFrameEncoder } from './types.js';
4
+ /** options for {@link LengthDelimitedCodec} */
5
+ export interface LengthDelimitedCodecOptions {
6
+ /**
7
+ * function that will be called to read the length of the frame
8
+ *
9
+ * @example `read.uint32le`
10
+ */
11
+ read?: (r: Bytes) => number | null;
12
+ /**
13
+ * function that will be called to write the length of the frame
14
+ *
15
+ * @example `write.uint32le`
16
+ */
17
+ write?: (w: ISyncWritable, n: number) => void;
18
+ }
19
+ /** a simple frame codec that uses a length prefix to separate frames */
20
+ export declare class LengthDelimitedCodec implements IFrameDecoder, IFrameEncoder {
21
+ #private;
22
+ constructor(options: LengthDelimitedCodecOptions);
23
+ decode(buf: Bytes): Uint8Array | null;
24
+ encode(frame: Uint8Array, into: ISyncWritable): void;
25
+ reset(): void;
26
+ }
@@ -0,0 +1,21 @@
1
+ import { IReadable } from '../types.js';
2
+ import { IFrameDecoder } from './types.js';
3
+ /** options for {@link FramedReader} */
4
+ export interface FramedReaderOptions {
5
+ initialBufferSize?: number;
6
+ readChunkSize?: number;
7
+ }
8
+ /** a reader that decodes frames one by one from a readable stream */
9
+ export declare class FramedReader<Frame> {
10
+ #private;
11
+ /**
12
+ * @param readable fuman readable stream to read from
13
+ * @param decoder frame decoder
14
+ * @param options extra options
15
+ */
16
+ constructor(readable: IReadable, decoder: IFrameDecoder<Frame>, options?: FramedReaderOptions);
17
+ /** read a next frame from the stream, or `null` if the stream ended */
18
+ read(): Promise<Frame | null>;
19
+ /** create an async iterator that yields frames */
20
+ [Symbol.asyncIterator](): AsyncIterator<Frame>;
21
+ }
@@ -0,0 +1,12 @@
1
+ import { Bytes } from '../bytes.js';
2
+ import { ISyncWritable } from '../types.js';
3
+ import { DelimiterCodecOptions } from './delimiter.js';
4
+ import { IFrameDecoder, IFrameEncoder } from './types.js';
5
+ /** wrapper over {@link DelimiterCodec} that handles text frames */
6
+ export declare class TextDelimiterCodec implements IFrameDecoder<string>, IFrameEncoder<string> {
7
+ #private;
8
+ constructor(delimiter: Uint8Array | string, options?: DelimiterCodecOptions);
9
+ decode(buf: Bytes, eof: boolean): string | null;
10
+ encode(data: string, into: ISyncWritable): void;
11
+ reset(): void;
12
+ }
@@ -0,0 +1,18 @@
1
+ import { MaybePromise } from '@fuman/utils';
2
+ import { Bytes } from '../bytes.js';
3
+ import { ISyncWritable } from '../types.js';
4
+ export interface IFrameDecoder<Frame = Uint8Array> {
5
+ /**
6
+ * Decode a frame from a buffer
7
+ *
8
+ * > **Important implementation notice**: When returning byte arrays, make sure that the returned array is **not**
9
+ * > a view into the original buffer, as the underlying buffer may get invalidated
10
+ */
11
+ decode: (buf: Bytes, eof: boolean) => MaybePromise<Frame | null>;
12
+ }
13
+ export interface IFrameEncoder<Frame = Uint8Array> {
14
+ /** Encode a frame into a writable stream */
15
+ encode: (frame: Frame, into: ISyncWritable) => MaybePromise<void>;
16
+ /** Reset the encoder, should it have any internal state */
17
+ reset: () => void;
18
+ }
package/codec/writer.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("@fuman/utils");
3
4
  const bytes = require("../bytes.cjs");
4
5
  class FramedWriter {
5
6
  #writable;
@@ -22,8 +23,9 @@ class FramedWriter {
22
23
  await this.#encoder.encode(frame, this.#buffer);
23
24
  const buffer = this.#buffer.result();
24
25
  if (buffer.length > 0) {
26
+ const copy = utils.u8.allocWith(buffer);
25
27
  this.#buffer.reset();
26
- await this.#writable.write(buffer);
28
+ await this.#writable.write(copy);
27
29
  }
28
30
  }
29
31
  }
@@ -0,0 +1,18 @@
1
+ import { IWritable } from '../types.js';
2
+ import { IFrameEncoder } from './types.js';
3
+ /** options for {@link FramedWriter} */
4
+ export interface FramedWriterOptions {
5
+ initialBufferSize?: number;
6
+ }
7
+ /** a writer that encodes frames one by one into a writable stream */
8
+ export declare class FramedWriter<Frame = Uint8Array> {
9
+ #private;
10
+ /**
11
+ * @param writable fuman writable stream to write to
12
+ * @param encoder frame encoder
13
+ * @param options extra options
14
+ */
15
+ constructor(writable: IWritable, encoder: IFrameEncoder<Frame>, options?: FramedWriterOptions);
16
+ /** write a frame to the stream */
17
+ write(frame: Frame): Promise<void>;
18
+ }
package/codec/writer.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { u8 } from "@fuman/utils";
1
2
  import { Bytes } from "../bytes.js";
2
3
  class FramedWriter {
3
4
  #writable;
@@ -20,8 +21,9 @@ class FramedWriter {
20
21
  await this.#encoder.encode(frame, this.#buffer);
21
22
  const buffer = this.#buffer.result();
22
23
  if (buffer.length > 0) {
24
+ const copy = u8.allocWith(buffer);
23
25
  this.#buffer.reset();
24
- await this.#writable.write(buffer);
26
+ await this.#writable.write(copy);
25
27
  }
26
28
  }
27
29
  }
package/errors.d.cts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Error thrown when trying to read more bytes than available.
3
+ *
4
+ * The part that was read is available in the `part` property.
5
+ */
6
+ export declare class PartialReadError extends RangeError {
7
+ /** the part that was read */
8
+ readonly part: Uint8Array;
9
+ constructor(
10
+ /** the part that was read */
11
+ part: Uint8Array, expectedLength: number);
12
+ }
package/index.d.cts ADDED
@@ -0,0 +1,12 @@
1
+ import * as read from './read/index.js';
2
+ import * as write from './write/index.js';
3
+ export * from './bits/index.js';
4
+ export * from './buf-reader.js';
5
+ export * from './bytes.js';
6
+ export * from './codec/index.js';
7
+ export * from './errors.js';
8
+ export * from './read/adapters.js';
9
+ export * from './reader-with-final.js';
10
+ export * from './types.js';
11
+ export * from './write/adapters.js';
12
+ export { read, write };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fuman/io",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.8",
5
5
  "description": "experimental i/o abstractions",
6
6
  "license": "MIT",
7
7
  "scripts": {},
@@ -0,0 +1,7 @@
1
+ import { IClosable, IReadable, ISyncReadable } from '../types.js';
2
+ /** create an async readable stream from a sync readable stream */
3
+ export declare function fumanSyncReadableToAsync(readable: ISyncReadable): IReadable;
4
+ /** convert a web ReadableStream to a fuman readable stream */
5
+ export declare function webReadableToFuman(readable: ReadableStream<Uint8Array>): IReadable & IClosable;
6
+ /** convert a fuman readable stream to a web ReadableStream */
7
+ export declare function fumanReadableToWeb(readable: IReadable): ReadableStream<Uint8Array>;
@@ -0,0 +1 @@
1
+ export * from './strings.js';
@@ -0,0 +1,18 @@
1
+ import { IReadable } from '../../types.js';
2
+ /**
3
+ * read exactly N bytes from the source
4
+ *
5
+ * @param readable fuman readable stream
6
+ * @param length length of the buffer to read, or a buffer to read into (when a number is passed, a new buffer will be allocated)
7
+ * @param onEof what to do when the end of the stream is reached
8
+ * - `error` - throw an {@link PartialReadError}
9
+ * - `truncate` - truncate the buffer to the number of bytes that were read. note that this might return 0 bytes
10
+ */
11
+ export declare function exactly(readable: IReadable, length: number | Uint8Array, onEof?: 'error' | 'truncate'): Promise<Uint8Array>;
12
+ /**
13
+ * read the source until it ends, and return the buffer
14
+ *
15
+ * @param readable fuman readable stream
16
+ * @param chunkSize size of the chunks to read
17
+ */
18
+ export declare function untilEnd(readable: IReadable, chunkSize?: number): Promise<Uint8Array>;
@@ -0,0 +1,4 @@
1
+ import * as async from './async/index.js';
2
+ export * from './numbers.js';
3
+ export * from './strings.js';
4
+ export { async };
@@ -0,0 +1,53 @@
1
+ import { ISyncReadable } from '../types.js';
2
+ /** read a uint8 from the source */
3
+ export declare function uint8(readable: ISyncReadable): number;
4
+ /** read an int8 from the source (fuman readable stream or a buffer) */
5
+ export declare function int8(readable: ISyncReadable | Uint8Array): number;
6
+ /** read a uint16 (little endian) from the source (fuman readable stream or a buffer) */
7
+ export declare function uint16le(readable: ISyncReadable | Uint8Array): number;
8
+ /** read a uint16 (big endian) from the source (fuman readable stream or a buffer) */
9
+ export declare function uint16be(readable: ISyncReadable | Uint8Array): number;
10
+ /** read a uint24 (little endian) from the source (fuman readable stream or a buffer) */
11
+ export declare function uint24le(readable: ISyncReadable | Uint8Array): number;
12
+ /** read a uint24 (big endian) from the source (fuman readable stream or a buffer) */
13
+ export declare function uint24be(readable: ISyncReadable | Uint8Array): number;
14
+ /** read a uint32 (little endian) from the source (fuman readable stream or a buffer) */
15
+ export declare function uint32le(readable: ISyncReadable | Uint8Array): number;
16
+ /** read a uint32 (big endian) from the source (fuman readable stream or a buffer) */
17
+ export declare function uint32be(readable: ISyncReadable | Uint8Array): number;
18
+ /** read a uint64 (little endian) from the source (fuman readable stream or a buffer) */
19
+ export declare function uint64le(readable: ISyncReadable | Uint8Array): bigint;
20
+ /** read a uint64 (big endian) from the source (fuman readable stream or a buffer) */
21
+ export declare function uint64be(readable: ISyncReadable | Uint8Array): bigint;
22
+ /** read an int16 (little endian) from the source (fuman readable stream or a buffer) */
23
+ export declare function int16le(readable: ISyncReadable | Uint8Array): number;
24
+ /** read an int16 (big endian) from the source (fuman readable stream or a buffer) */
25
+ export declare function int16be(readable: ISyncReadable | Uint8Array): number;
26
+ /** read an int24 (little endian) from the source (fuman readable stream or a buffer) */
27
+ export declare function int24le(readable: ISyncReadable | Uint8Array): number;
28
+ /** read an int24 (big endian) from the source (fuman readable stream or a buffer) */
29
+ export declare function int24be(readable: ISyncReadable | Uint8Array): number;
30
+ /** read an int32 (little endian) from the source (fuman readable stream or a buffer) */
31
+ export declare function int32le(readable: ISyncReadable | Uint8Array): number;
32
+ /** read an int32 (big endian) from the source (fuman readable stream or a buffer) */
33
+ export declare function int32be(readable: ISyncReadable | Uint8Array): number;
34
+ /** read an int64 (little endian) from the source (fuman readable stream or a buffer) */
35
+ export declare function int64le(readable: ISyncReadable | Uint8Array): bigint;
36
+ /** read an int64 (big endian) from the source (fuman readable stream or a buffer) */
37
+ export declare function int64be(readable: ISyncReadable | Uint8Array): bigint;
38
+ /** read a variable-size uint (little endian) from the source (fuman readable stream or a buffer) */
39
+ export declare function uintle(readable: ISyncReadable | Uint8Array, size: number): bigint;
40
+ /** read a variable-size uint (big endian) from the source (fuman readable stream or a buffer) */
41
+ export declare function uintbe(readable: ISyncReadable | Uint8Array, size: number): bigint;
42
+ /** read a variable-size int (big endian) from the source (fuman readable stream or a buffer) */
43
+ export declare function intbe(readable: ISyncReadable | Uint8Array, size: number): bigint;
44
+ /** read a variable-size int (little endian) from the source (fuman readable stream or a buffer) */
45
+ export declare function intle(readable: ISyncReadable | Uint8Array, size: number): bigint;
46
+ /** read a float32 (little endian) from the source (fuman readable stream or a buffer) */
47
+ export declare function float32le(readable: ISyncReadable | Uint8Array): number;
48
+ /** read a float32 (big endian) from the source (fuman readable stream or a buffer) */
49
+ export declare function float32be(readable: ISyncReadable | Uint8Array): number;
50
+ /** read a float64 (little endian) from the source (fuman readable stream or a buffer) */
51
+ export declare function float64le(readable: ISyncReadable | Uint8Array): number;
52
+ /** read a float64 (big endian) from the source (fuman readable stream or a buffer) */
53
+ export declare function float64be(readable: ISyncReadable | Uint8Array): number;
@@ -0,0 +1,9 @@
1
+ import { ISyncReadable } from '../types.js';
2
+ export declare function exactly(readable: ISyncReadable, length: number): Uint8Array;
3
+ export declare function rawString(readable: ISyncReadable, length: number): string;
4
+ export declare function utf8String(readable: ISyncReadable, length: number): string;
5
+ export declare function untilCondition(readable: ISyncReadable, condition: (byte: number) => boolean): Uint8Array;
6
+ export declare function untilEnd(readable: ISyncReadable, chunkSize?: number): Uint8Array;
7
+ export declare function untilZero(readable: ISyncReadable): Uint8Array;
8
+ export declare function cUtf8String(readable: ISyncReadable): string;
9
+ export declare function lengthPrefixed(readLength: (readable: ISyncReadable) => number, readable: ISyncReadable): Uint8Array;
@@ -0,0 +1,21 @@
1
+ import { IReadable } from './types.js';
2
+ /** result of {@link ReaderWithFinal#readWithFinal} */
3
+ export interface ReaderWithFinalResult {
4
+ /** number of bytes read */
5
+ readonly nread: number;
6
+ /** whether this was the last chunk */
7
+ readonly final: boolean;
8
+ }
9
+ /**
10
+ * a reader that reads one read ahead, allowing the caller to know
11
+ * whether the chunk being read is the last one
12
+ */
13
+ export declare class ReaderWithFinal implements IReadable {
14
+ #private;
15
+ constructor(readable: IReadable, params?: {
16
+ internalBufferSize?: number;
17
+ });
18
+ /** read a chunk of data, and whether it is the last one */
19
+ readWithFinal(into: Uint8Array): Promise<ReaderWithFinalResult>;
20
+ read(into: Uint8Array): Promise<number>;
21
+ }
package/streams.d.cts ADDED
@@ -0,0 +1 @@
1
+ export declare function isByobCapableStream(stream: ReadableStream<Uint8Array>): boolean;
package/types.d.cts ADDED
@@ -0,0 +1,69 @@
1
+ /** A synchronous readable stream */
2
+ export interface ISyncReadable {
3
+ /**
4
+ * Read the specified number of bytes from the source
5
+ * and return them as a Uint8Array.
6
+ *
7
+ * **The returned Uint8Array**:
8
+ * - *may* be a view into a larger buffer
9
+ * - is only valid until the next call to `readSync`
10
+ * - may be smaller than the requested number of bytes if the end of the source is reached.
11
+ * > these constraints allow for more efficient zero-copy implementations in many cases
12
+ *
13
+ * @param bytes The number of bytes to read
14
+ * @returns Uint8Array containing the bytes that were read.
15
+ */
16
+ readSync: (bytes: number) => Uint8Array;
17
+ }
18
+ /** A readable stream */
19
+ export interface IReadable {
20
+ /**
21
+ * Read data from the underlying source into the provided Uint8Array,
22
+ * up to the length of the array, and return the number of bytes read.
23
+ *
24
+ * If there are no bytes available currently, the implementation is supposed to wait
25
+ * until at least one byte is available, and only then resolve the promise.
26
+ * Resolving the promise with a zero-length Uint8Array is marking the end of the source.
27
+ *
28
+ * @param bytes The number of bytes to read
29
+ * @returns Uint8Array containing the bytes that were read.
30
+ */
31
+ read: (into: Uint8Array) => Promise<number>;
32
+ }
33
+ /** Something that can be closed */
34
+ export interface IClosable {
35
+ /**
36
+ * Close the underlying source.
37
+ */
38
+ close: () => void;
39
+ }
40
+ /** A synchronous writable stream */
41
+ export interface ISyncWritable {
42
+ /**
43
+ * Write the specified number of bytes to the underlying source.
44
+ *
45
+ * The implementation is supposed to make sure there are at least `bytes` bytes
46
+ * available in the underlying source and return a Uint8Array that can be written to.
47
+ * The returned Uint8Array must be valid at least until the next call to `writeSync`
48
+ * or `disposeWriteSync`.
49
+ *
50
+ * If the caller writes less than `bytes` bytes to the returned Uint8Array,
51
+ * `disposeWriteSync` must be called with the number of bytes that were actually written.
52
+ *
53
+ * @param bytes The number of bytes to write
54
+ * @returns Uint8Array of length `bytes` that can be written to
55
+ */
56
+ writeSync: (bytes: number) => Uint8Array;
57
+ /**
58
+ * Explicitly dispose of the buffer that was returned by the last call to `writeSync`.
59
+ *
60
+ * If less than `bytes` bytes were written to the buffer, the number of bytes that were
61
+ * written must be passed as the `written` argument.
62
+ */
63
+ disposeWriteSync: (written?: number) => void;
64
+ }
65
+ /** A writable stream */
66
+ export interface IWritable {
67
+ /** Write bytes to the underlying stream, resolving once the write is complete */
68
+ write: (bytes: Uint8Array) => Promise<void>;
69
+ }
@@ -0,0 +1,4 @@
1
+ import { IClosable, ISyncWritable, IWritable } from '../types.js';
2
+ export declare function fumanSyncWritableToAsync(sync: ISyncWritable): IWritable;
3
+ export declare function webWritableToFuman(writable: WritableStream<Uint8Array>): IWritable & IClosable;
4
+ export declare function fumanWritableToWeb(writable: IWritable): WritableStream<Uint8Array>;
@@ -0,0 +1,3 @@
1
+ export * from './numbers.js';
2
+ export * from './pipe.js';
3
+ export * from './strings.js';
@@ -0,0 +1,53 @@
1
+ import { ISyncWritable } from '../types.js';
2
+ /** write a uint8 to the target (fuman writable stream or a buffer) */
3
+ export declare function uint8(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
4
+ /** write an int8 to the target (fuman writable stream or a buffer) */
5
+ export declare function int8(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
6
+ /** write a uint16 (little endian) to the target (fuman writable stream or a buffer) */
7
+ export declare function uint16le(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
8
+ /** write a uint16 (big endian) to the target (fuman writable stream or a buffer) */
9
+ export declare function uint16be(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
10
+ /** write an int16 (little endian) to the target (fuman writable stream or a buffer) */
11
+ export declare function int16le(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
12
+ /** write an int16 (big endian) to the target (fuman writable stream or a buffer) */
13
+ export declare function int16be(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
14
+ /** write a uint24 (little endian) to the target (fuman writable stream or a buffer) */
15
+ export declare function uint24le(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
16
+ /** write a uint24 (big endian) to the target (fuman writable stream or a buffer) */
17
+ export declare function uint24be(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
18
+ /** write an int24 (little endian) to the target (fuman writable stream or a buffer) */
19
+ export declare function int24le(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
20
+ /** write an int24 (big endian) to the target (fuman writable stream or a buffer) */
21
+ export declare function int24be(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
22
+ /** write a uint32 (little endian) to the target (fuman writable stream or a buffer) */
23
+ export declare function uint32le(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
24
+ /** write a uint32 (big endian) to the target (fuman writable stream or a buffer) */
25
+ export declare function uint32be(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
26
+ /** write an int32 (little endian) to the target (fuman writable stream or a buffer) */
27
+ export declare function int32le(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
28
+ /** write an int32 (big endian) to the target (fuman writable stream or a buffer) */
29
+ export declare function int32be(writable: ISyncWritable | Uint8Array, value: number, noAssert?: boolean): void;
30
+ /** write a uint64 (little endian) to the target (fuman writable stream or a buffer) */
31
+ export declare function uint64le(writable: ISyncWritable | Uint8Array, value: bigint, noAssert?: boolean): void;
32
+ /** write a uint64 (big endian) to the target (fuman writable stream or a buffer) */
33
+ export declare function uint64be(writable: ISyncWritable | Uint8Array, value: bigint, noAssert?: boolean): void;
34
+ /** write an int64 (little endian) to the target (fuman writable stream or a buffer) */
35
+ export declare function int64le(writable: ISyncWritable | Uint8Array, value: bigint, noAssert?: boolean): void;
36
+ /** write an int64 (big endian) to the target (fuman writable stream or a buffer) */
37
+ export declare function int64be(writable: ISyncWritable | Uint8Array, value: bigint, noAssert?: boolean): void;
38
+ /** write a variable-size uint (little endian) to the target (fuman writable stream or a buffer) */
39
+ export declare function uintle(writable: ISyncWritable | Uint8Array, size: number, value: bigint, noAssert?: boolean): void;
40
+ /** write a variable-size uint (big endian) to the target (fuman writable stream or a buffer) */
41
+ export declare function uintbe(writable: ISyncWritable | Uint8Array, size: number, value: bigint, noAssert?: boolean): void;
42
+ /** write a variable-size int (little endian) to the target (fuman writable stream or a buffer) */
43
+ export declare function intle(writable: ISyncWritable | Uint8Array, size: number, value: bigint, noAssert?: boolean): void;
44
+ /** write a variable-size int (big endian) to the target (fuman writable stream or a buffer) */
45
+ export declare function intbe(writable: ISyncWritable | Uint8Array, size: number, value: bigint, noAssert?: boolean): void;
46
+ /** write a float32 (little endian) to the target (fuman writable stream or a buffer) */
47
+ export declare function float32le(writable: ISyncWritable | Uint8Array, value: number): void;
48
+ /** write a float32 (big endian) to the target (fuman writable stream or a buffer) */
49
+ export declare function float32be(writable: ISyncWritable | Uint8Array, value: number): void;
50
+ /** write a float64 (little endian) to the target (fuman writable stream or a buffer) */
51
+ export declare function float64le(writable: ISyncWritable | Uint8Array, value: number): void;
52
+ /** write a float64 (big endian) to the target (fuman writable stream or a buffer) */
53
+ export declare function float64be(writable: ISyncWritable | Uint8Array, value: number): void;
@@ -0,0 +1,3 @@
1
+ import { IReadable, IWritable } from '../types.js';
2
+ /** pipe the contents of a readable stream (until it ends) into a writable stream */
3
+ export declare function pipe(into: IWritable, readable: IReadable): Promise<void>;
@@ -0,0 +1,11 @@
1
+ import { ISyncWritable } from '../types.js';
2
+ /** write a buffer to the stream */
3
+ export declare function bytes(writable: ISyncWritable, bytes: Uint8Array): void;
4
+ /** write a buffer to the stream, but in reverse order */
5
+ export declare function bytesReversed(writable: ISyncWritable, bytes: Uint8Array): void;
6
+ /** write a raw string to the stream (`.charCodeAt` is used to get the codepoints) */
7
+ export declare function rawString(writable: ISyncWritable, str: string): void;
8
+ /** write a utf8-encoded string to the stream */
9
+ export declare function utf8String(writable: ISyncWritable, str: string): void;
10
+ /** write a utf8-encoded string to the stream, with a null terminator */
11
+ export declare function cUtf8String(writable: ISyncWritable, str: string): void;