strtok3 8.0.0 → 8.0.2

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/lib/core.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
2
- import { BufferTokenizer } from './BufferTokenizer.js';
3
- import type { ITokenizerOptions } from './types.js';
4
- import type { ReadableStream } from 'node:stream/web';
5
- import type { Readable } from 'node:stream';
6
- export { EndOfStreamError } from 'peek-readable';
7
- export type { ITokenizer, IFileInfo, ITokenizerOptions, OnClose } from './types.js';
8
- export type { IToken, IGetToken } from '@tokenizer/token';
9
- /**
10
- * Construct ReadStreamTokenizer from given Stream.
11
- * Will set fileSize, if provided given Stream has set the .path property/
12
- * @param stream - Read from Node.js Stream.Readable
13
- * @param options - Tokenizer options
14
- * @returns ReadStreamTokenizer
15
- */
16
- export declare function fromStream(stream: Readable, options?: ITokenizerOptions): ReadStreamTokenizer;
17
- /**
18
- * Construct ReadStreamTokenizer from given ReadableStream (WebStream API).
19
- * Will set fileSize, if provided given Stream has set the .path property/
20
- * @param webStream - Read from Node.js Stream.Readable
21
- * @param options - Tokenizer options
22
- * @returns ReadStreamTokenizer
23
- */
24
- export declare function fromWebStream(webStream: ReadableStream<Uint8Array>, options?: ITokenizerOptions): ReadStreamTokenizer;
25
- /**
26
- * Construct ReadStreamTokenizer from given Buffer.
27
- * @param uint8Array - Uint8Array to tokenize
28
- * @param options - Tokenizer options
29
- * @returns BufferTokenizer
30
- */
31
- export declare function fromBuffer(uint8Array: Uint8Array, options?: ITokenizerOptions): BufferTokenizer;
package/lib/core.js DELETED
@@ -1,33 +0,0 @@
1
- import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
2
- import { BufferTokenizer } from './BufferTokenizer.js';
3
- import { StreamReader, WebStreamReader } from 'peek-readable';
4
- export { EndOfStreamError } from 'peek-readable';
5
- /**
6
- * Construct ReadStreamTokenizer from given Stream.
7
- * Will set fileSize, if provided given Stream has set the .path property/
8
- * @param stream - Read from Node.js Stream.Readable
9
- * @param options - Tokenizer options
10
- * @returns ReadStreamTokenizer
11
- */
12
- export function fromStream(stream, options) {
13
- return new ReadStreamTokenizer(new StreamReader(stream), options);
14
- }
15
- /**
16
- * Construct ReadStreamTokenizer from given ReadableStream (WebStream API).
17
- * Will set fileSize, if provided given Stream has set the .path property/
18
- * @param webStream - Read from Node.js Stream.Readable
19
- * @param options - Tokenizer options
20
- * @returns ReadStreamTokenizer
21
- */
22
- export function fromWebStream(webStream, options) {
23
- return new ReadStreamTokenizer(new WebStreamReader(webStream), options);
24
- }
25
- /**
26
- * Construct ReadStreamTokenizer from given Buffer.
27
- * @param uint8Array - Uint8Array to tokenize
28
- * @param options - Tokenizer options
29
- * @returns BufferTokenizer
30
- */
31
- export function fromBuffer(uint8Array, options) {
32
- return new BufferTokenizer(uint8Array, options);
33
- }
package/lib/index.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { Readable } from 'node:stream';
2
- import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
3
- import { type ITokenizerOptions } from './core.js';
4
- export { fromFile } from './FileTokenizer.js';
5
- export { ITokenizer, EndOfStreamError, fromBuffer, fromWebStream, IFileInfo, ITokenizerOptions, OnClose } from './core.js';
6
- export { IToken, IGetToken } from '@tokenizer/token';
7
- /**
8
- * Construct ReadStreamTokenizer from given Stream.
9
- * Will set fileSize, if provided given Stream has set the .path property.
10
- * @param stream - Node.js Stream.Readable
11
- * @param options - Pass additional file information to the tokenizer
12
- * @returns Tokenizer
13
- */
14
- export declare function fromStream(stream: Readable, options?: ITokenizerOptions): Promise<ReadStreamTokenizer>;
package/lib/index.js DELETED
@@ -1,22 +0,0 @@
1
- import { stat as fsStat } from 'node:fs/promises';
2
- import { fromStream as coreFromStream } from './core.js';
3
- export { fromFile } from './FileTokenizer.js';
4
- export { EndOfStreamError, fromBuffer, fromWebStream } from './core.js';
5
- /**
6
- * Construct ReadStreamTokenizer from given Stream.
7
- * Will set fileSize, if provided given Stream has set the .path property.
8
- * @param stream - Node.js Stream.Readable
9
- * @param options - Pass additional file information to the tokenizer
10
- * @returns Tokenizer
11
- */
12
- export async function fromStream(stream, options) {
13
- var _a;
14
- const augmentedOptions = options !== null && options !== void 0 ? options : {};
15
- augmentedOptions.fileInfo = (_a = augmentedOptions.fileInfo) !== null && _a !== void 0 ? _a : {};
16
- if (stream.path) {
17
- const stat = await fsStat(stream.path);
18
- augmentedOptions.fileInfo.path = stream.path;
19
- augmentedOptions.fileInfo.size = stat.size;
20
- }
21
- return coreFromStream(stream, augmentedOptions);
22
- }
package/lib/types.d.ts DELETED
@@ -1,113 +0,0 @@
1
- import { IGetToken } from '@tokenizer/token';
2
- export interface IFileInfo {
3
- /**
4
- * File size in bytes
5
- */
6
- size?: number;
7
- /**
8
- * MIME-type of file
9
- */
10
- mimeType?: string;
11
- /**
12
- * File path
13
- */
14
- path?: string;
15
- /**
16
- * File URL
17
- */
18
- url?: string;
19
- }
20
- export interface IReadChunkOptions {
21
- /**
22
- * The offset in the buffer to start writing at; default is 0
23
- */
24
- offset?: number;
25
- /**
26
- * Number of bytes to read.
27
- */
28
- length?: number;
29
- /**
30
- * Position where to begin reading from the file.
31
- * Default it is `tokenizer.position`.
32
- * Position may not be less then `tokenizer.position`.
33
- */
34
- position?: number;
35
- /**
36
- * If set, will not throw an EOF error if not all of the requested data could be read
37
- */
38
- mayBeLess?: boolean;
39
- }
40
- /**
41
- * The tokenizer allows us to read or peek from the tokenizer-stream.
42
- * The tokenizer-stream is an abstraction of a stream, file or Buffer.
43
- */
44
- export interface ITokenizer {
45
- /**
46
- * Provide access to information of the underlying information stream or file.
47
- */
48
- fileInfo: IFileInfo;
49
- /**
50
- * Offset in bytes (= number of bytes read) since beginning of file or stream
51
- */
52
- position: number;
53
- /**
54
- * Peek (read ahead) buffer from tokenizer
55
- * @param buffer - Target buffer to fill with data peek from the tokenizer-stream
56
- * @param options - Read behaviour options
57
- * @returns Promise with number of bytes read
58
- */
59
- peekBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
60
- /**
61
- * Peek (read ahead) buffer from tokenizer
62
- * @param buffer - Target buffer to fill with data peeked from the tokenizer-stream
63
- * @param options - Additional read options
64
- * @returns Promise with number of bytes read
65
- */
66
- readBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
67
- /**
68
- * Peek a token from the tokenizer-stream.
69
- * @param token - Token to peek from the tokenizer-stream.
70
- * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
71
- * @param maybeless - If set, will not throw an EOF error if the less then the requested length could be read.
72
- */
73
- peekToken<T>(token: IGetToken<T>, position?: number | null, maybeless?: boolean): Promise<T>;
74
- /**
75
- * Read a token from the tokenizer-stream.
76
- * @param token - Token to peek from the tokenizer-stream.
77
- * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
78
- */
79
- readToken<T>(token: IGetToken<T>, position?: number): Promise<T>;
80
- /**
81
- * Peek a numeric token from the stream
82
- * @param token - Numeric token
83
- * @returns Promise with number
84
- */
85
- peekNumber(token: IGetToken<number>): Promise<number>;
86
- /**
87
- * Read a numeric token from the stream
88
- * @param token - Numeric token
89
- * @returns Promise with number
90
- */
91
- readNumber(token: IGetToken<number>): Promise<number>;
92
- /**
93
- * Ignore given number of bytes
94
- * @param length - Number of bytes ignored
95
- */
96
- ignore(length: number): Promise<number>;
97
- /**
98
- * Clean up resources.
99
- * It does not close the stream for StreamReader, but is does close the file-descriptor.
100
- */
101
- close(): Promise<void>;
102
- }
103
- export type OnClose = () => Promise<void>;
104
- export interface ITokenizerOptions {
105
- /**
106
- * Pass additional file information to the tokenizer
107
- */
108
- fileInfo?: IFileInfo;
109
- /**
110
- * On tokenizer close handler
111
- */
112
- onClose?: OnClose;
113
- }
package/lib/types.js DELETED
@@ -1 +0,0 @@
1
- export {};