strtok3 8.0.1 → 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/LICENSE +14 -14
- package/README.md +317 -317
- package/package.json +89 -100
- package/lib/AbstractTokenizer.d.ts +0 -75
- package/lib/AbstractTokenizer.js +0 -108
- package/lib/BufferTokenizer.d.ts +0 -26
- package/lib/BufferTokenizer.js +0 -51
- package/lib/FileTokenizer.d.ts +0 -23
- package/lib/FileTokenizer.js +0 -48
- package/lib/ReadStreamTokenizer.d.ts +0 -27
- package/lib/ReadStreamTokenizer.js +0 -92
- package/lib/core.d.ts +0 -32
- package/lib/core.js +0 -34
- package/lib/index.d.ts +0 -15
- package/lib/index.js +0 -22
- package/lib/types.d.ts +0 -113
- package/lib/types.js +0 -1
package/lib/core.d.ts
DELETED
|
@@ -1,32 +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, IReadChunkOptions, OnClose } from './types.js';
|
|
8
|
-
export type { IToken, IGetToken } from '@tokenizer/token';
|
|
9
|
-
export { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
10
|
-
/**
|
|
11
|
-
* Construct ReadStreamTokenizer from given Stream.
|
|
12
|
-
* Will set fileSize, if provided given Stream has set the .path property/
|
|
13
|
-
* @param stream - Read from Node.js Stream.Readable
|
|
14
|
-
* @param options - Tokenizer options
|
|
15
|
-
* @returns ReadStreamTokenizer
|
|
16
|
-
*/
|
|
17
|
-
export declare function fromStream(stream: Readable, options?: ITokenizerOptions): ReadStreamTokenizer;
|
|
18
|
-
/**
|
|
19
|
-
* Construct ReadStreamTokenizer from given ReadableStream (WebStream API).
|
|
20
|
-
* Will set fileSize, if provided given Stream has set the .path property/
|
|
21
|
-
* @param webStream - Read from Node.js Stream.Readable
|
|
22
|
-
* @param options - Tokenizer options
|
|
23
|
-
* @returns ReadStreamTokenizer
|
|
24
|
-
*/
|
|
25
|
-
export declare function fromWebStream(webStream: ReadableStream<Uint8Array>, options?: ITokenizerOptions): ReadStreamTokenizer;
|
|
26
|
-
/**
|
|
27
|
-
* Construct ReadStreamTokenizer from given Buffer.
|
|
28
|
-
* @param uint8Array - Uint8Array to tokenize
|
|
29
|
-
* @param options - Tokenizer options
|
|
30
|
-
* @returns BufferTokenizer
|
|
31
|
-
*/
|
|
32
|
-
export declare function fromBuffer(uint8Array: Uint8Array, options?: ITokenizerOptions): BufferTokenizer;
|
package/lib/core.js
DELETED
|
@@ -1,34 +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
|
-
export { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
6
|
-
/**
|
|
7
|
-
* Construct ReadStreamTokenizer from given Stream.
|
|
8
|
-
* Will set fileSize, if provided given Stream has set the .path property/
|
|
9
|
-
* @param stream - Read from Node.js Stream.Readable
|
|
10
|
-
* @param options - Tokenizer options
|
|
11
|
-
* @returns ReadStreamTokenizer
|
|
12
|
-
*/
|
|
13
|
-
export function fromStream(stream, options) {
|
|
14
|
-
return new ReadStreamTokenizer(new StreamReader(stream), options);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Construct ReadStreamTokenizer from given ReadableStream (WebStream API).
|
|
18
|
-
* Will set fileSize, if provided given Stream has set the .path property/
|
|
19
|
-
* @param webStream - Read from Node.js Stream.Readable
|
|
20
|
-
* @param options - Tokenizer options
|
|
21
|
-
* @returns ReadStreamTokenizer
|
|
22
|
-
*/
|
|
23
|
-
export function fromWebStream(webStream, options) {
|
|
24
|
-
return new ReadStreamTokenizer(new WebStreamReader(webStream), options);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Construct ReadStreamTokenizer from given Buffer.
|
|
28
|
-
* @param uint8Array - Uint8Array to tokenize
|
|
29
|
-
* @param options - Tokenizer options
|
|
30
|
-
* @returns BufferTokenizer
|
|
31
|
-
*/
|
|
32
|
-
export function fromBuffer(uint8Array, options) {
|
|
33
|
-
return new BufferTokenizer(uint8Array, options);
|
|
34
|
-
}
|
package/lib/index.d.ts
DELETED
|
@@ -1,15 +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 { EndOfStreamError, fromBuffer, fromWebStream, AbstractTokenizer } from './core.js';
|
|
6
|
-
export type { ITokenizer, IFileInfo, ITokenizerOptions, IReadChunkOptions, OnClose } from './core.js';
|
|
7
|
-
export type { IToken, IGetToken } from '@tokenizer/token';
|
|
8
|
-
/**
|
|
9
|
-
* Construct ReadStreamTokenizer from given Stream.
|
|
10
|
-
* Will set fileSize, if provided given Stream has set the .path property.
|
|
11
|
-
* @param stream - Node.js Stream.Readable
|
|
12
|
-
* @param options - Pass additional file information to the tokenizer
|
|
13
|
-
* @returns Tokenizer
|
|
14
|
-
*/
|
|
15
|
-
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, AbstractTokenizer } 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 {};
|