strtok3 7.0.0-alpha.7 → 7.0.0
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 +306 -300
- package/lib/AbstractTokenizer.d.ts +69 -69
- package/lib/AbstractTokenizer.js +101 -101
- package/lib/BufferTokenizer.d.ts +26 -26
- package/lib/BufferTokenizer.js +51 -51
- package/lib/FileTokenizer.d.ts +22 -22
- package/lib/FileTokenizer.js +50 -50
- package/lib/FsPromise.d.ts +19 -18
- package/lib/FsPromise.js +69 -69
- package/lib/ReadStreamTokenizer.d.ts +28 -28
- package/lib/ReadStreamTokenizer.js +94 -94
- package/lib/core.d.ts +23 -23
- package/lib/core.js +23 -23
- package/lib/index.d.ts +15 -15
- package/lib/index.js +20 -20
- package/lib/types.d.ts +103 -103
- package/lib/types.js +1 -1
- package/package.json +94 -95
package/lib/FsPromise.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module convert fs functions to promise based functions
|
|
3
|
-
*/
|
|
4
|
-
/// <reference types="node" />
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare const
|
|
12
|
-
export declare
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function
|
|
18
|
-
export declare function
|
|
1
|
+
/**
|
|
2
|
+
* Module convert fs functions to promise based functions
|
|
3
|
+
*/
|
|
4
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
5
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
export interface IReadResult {
|
|
8
|
+
bytesRead: number;
|
|
9
|
+
buffer: Uint8Array;
|
|
10
|
+
}
|
|
11
|
+
export declare const pathExists: typeof fs.existsSync;
|
|
12
|
+
export declare const createReadStream: typeof fs.createReadStream;
|
|
13
|
+
export declare function stat(path: fs.PathLike): Promise<fs.Stats>;
|
|
14
|
+
export declare function close(fd: number): Promise<void>;
|
|
15
|
+
export declare function open(path: fs.PathLike, mode: fs.Mode): Promise<number>;
|
|
16
|
+
export declare function read(fd: number, buffer: Uint8Array, offset: number, length: number, position: number): Promise<IReadResult>;
|
|
17
|
+
export declare function writeFile(path: fs.PathLike, data: Buffer | string): Promise<void>;
|
|
18
|
+
export declare function writeFileSync(path: fs.PathLike, data: Buffer | string): void;
|
|
19
|
+
export declare function readFile(path: fs.PathLike): Promise<Buffer>;
|
package/lib/FsPromise.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module convert fs functions to promise based functions
|
|
3
|
-
*/
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
export const pathExists = fs.existsSync;
|
|
6
|
-
export const createReadStream = fs.createReadStream;
|
|
7
|
-
export async function stat(path) {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
fs.stat(path, (err, stats) => {
|
|
10
|
-
if (err)
|
|
11
|
-
reject(err);
|
|
12
|
-
else
|
|
13
|
-
resolve(stats);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
export async function close(fd) {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
fs.close(fd, err => {
|
|
20
|
-
if (err)
|
|
21
|
-
reject(err);
|
|
22
|
-
else
|
|
23
|
-
resolve();
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
export async function open(path, mode) {
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
fs.open(path, mode, (err, fd) => {
|
|
30
|
-
if (err)
|
|
31
|
-
reject(err);
|
|
32
|
-
else
|
|
33
|
-
resolve(fd);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
export async function read(fd, buffer, offset, length, position) {
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
fs.read(fd, buffer, offset, length, position, (err, bytesRead, _buffer) => {
|
|
40
|
-
if (err)
|
|
41
|
-
reject(err);
|
|
42
|
-
else
|
|
43
|
-
resolve({ bytesRead, buffer: _buffer });
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
export async function writeFile(path, data) {
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
fs.writeFile(path, data, err => {
|
|
50
|
-
if (err)
|
|
51
|
-
reject(err);
|
|
52
|
-
else
|
|
53
|
-
resolve();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
export function writeFileSync(path, data) {
|
|
58
|
-
fs.writeFileSync(path, data);
|
|
59
|
-
}
|
|
60
|
-
export async function readFile(path) {
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
fs.readFile(path, (err, buffer) => {
|
|
63
|
-
if (err)
|
|
64
|
-
reject(err);
|
|
65
|
-
else
|
|
66
|
-
resolve(buffer);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Module convert fs functions to promise based functions
|
|
3
|
+
*/
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
export const pathExists = fs.existsSync;
|
|
6
|
+
export const createReadStream = fs.createReadStream;
|
|
7
|
+
export async function stat(path) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
fs.stat(path, (err, stats) => {
|
|
10
|
+
if (err)
|
|
11
|
+
reject(err);
|
|
12
|
+
else
|
|
13
|
+
resolve(stats);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export async function close(fd) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
fs.close(fd, err => {
|
|
20
|
+
if (err)
|
|
21
|
+
reject(err);
|
|
22
|
+
else
|
|
23
|
+
resolve();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export async function open(path, mode) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
fs.open(path, mode, (err, fd) => {
|
|
30
|
+
if (err)
|
|
31
|
+
reject(err);
|
|
32
|
+
else
|
|
33
|
+
resolve(fd);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export async function read(fd, buffer, offset, length, position) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
fs.read(fd, buffer, offset, length, position, (err, bytesRead, _buffer) => {
|
|
40
|
+
if (err)
|
|
41
|
+
reject(err);
|
|
42
|
+
else
|
|
43
|
+
resolve({ bytesRead, buffer: _buffer });
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export async function writeFile(path, data) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
fs.writeFile(path, data, err => {
|
|
50
|
+
if (err)
|
|
51
|
+
reject(err);
|
|
52
|
+
else
|
|
53
|
+
resolve();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export function writeFileSync(path, data) {
|
|
58
|
+
fs.writeFileSync(path, data);
|
|
59
|
+
}
|
|
60
|
+
export async function readFile(path) {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
fs.readFile(path, (err, buffer) => {
|
|
63
|
+
if (err)
|
|
64
|
+
reject(err);
|
|
65
|
+
else
|
|
66
|
+
resolve(buffer);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
3
|
-
import { Readable } from 'node:stream';
|
|
4
|
-
import { IFileInfo, IReadChunkOptions } from './types.js';
|
|
5
|
-
export declare class ReadStreamTokenizer extends AbstractTokenizer {
|
|
6
|
-
private streamReader;
|
|
7
|
-
constructor(stream: Readable, fileInfo?: IFileInfo);
|
|
8
|
-
/**
|
|
9
|
-
* Get file information, an HTTP-client may implement this doing a HEAD request
|
|
10
|
-
* @return Promise with file information
|
|
11
|
-
*/
|
|
12
|
-
getFileInfo(): Promise<IFileInfo>;
|
|
13
|
-
/**
|
|
14
|
-
* Read buffer from tokenizer
|
|
15
|
-
* @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
|
|
16
|
-
* @param options - Read behaviour options
|
|
17
|
-
* @returns Promise with number of bytes read
|
|
18
|
-
*/
|
|
19
|
-
readBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
|
20
|
-
/**
|
|
21
|
-
* Peek (read ahead) buffer from tokenizer
|
|
22
|
-
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
|
23
|
-
* @param options - Read behaviour options
|
|
24
|
-
* @returns Promise with number of bytes peeked
|
|
25
|
-
*/
|
|
26
|
-
peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
|
27
|
-
ignore(length: number): Promise<number>;
|
|
28
|
-
}
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
import { IFileInfo, IReadChunkOptions } from './types.js';
|
|
5
|
+
export declare class ReadStreamTokenizer extends AbstractTokenizer {
|
|
6
|
+
private streamReader;
|
|
7
|
+
constructor(stream: Readable, fileInfo?: IFileInfo);
|
|
8
|
+
/**
|
|
9
|
+
* Get file information, an HTTP-client may implement this doing a HEAD request
|
|
10
|
+
* @return Promise with file information
|
|
11
|
+
*/
|
|
12
|
+
getFileInfo(): Promise<IFileInfo>;
|
|
13
|
+
/**
|
|
14
|
+
* Read buffer from tokenizer
|
|
15
|
+
* @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
|
|
16
|
+
* @param options - Read behaviour options
|
|
17
|
+
* @returns Promise with number of bytes read
|
|
18
|
+
*/
|
|
19
|
+
readBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
|
20
|
+
/**
|
|
21
|
+
* Peek (read ahead) buffer from tokenizer
|
|
22
|
+
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
|
23
|
+
* @param options - Read behaviour options
|
|
24
|
+
* @returns Promise with number of bytes peeked
|
|
25
|
+
*/
|
|
26
|
+
peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
|
27
|
+
ignore(length: number): Promise<number>;
|
|
28
|
+
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
2
|
-
import { EndOfStreamError, StreamReader } from 'peek-readable';
|
|
3
|
-
const maxBufferSize = 256000;
|
|
4
|
-
export class ReadStreamTokenizer extends AbstractTokenizer {
|
|
5
|
-
constructor(stream, fileInfo) {
|
|
6
|
-
super(fileInfo);
|
|
7
|
-
this.streamReader = new StreamReader(stream);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Get file information, an HTTP-client may implement this doing a HEAD request
|
|
11
|
-
* @return Promise with file information
|
|
12
|
-
*/
|
|
13
|
-
async getFileInfo() {
|
|
14
|
-
return this.fileInfo;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Read buffer from tokenizer
|
|
18
|
-
* @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
|
|
19
|
-
* @param options - Read behaviour options
|
|
20
|
-
* @returns Promise with number of bytes read
|
|
21
|
-
*/
|
|
22
|
-
async readBuffer(uint8Array, options) {
|
|
23
|
-
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
24
|
-
const skipBytes = normOptions.position - this.position;
|
|
25
|
-
if (skipBytes > 0) {
|
|
26
|
-
await this.ignore(skipBytes);
|
|
27
|
-
return this.readBuffer(uint8Array, options);
|
|
28
|
-
}
|
|
29
|
-
else if (skipBytes < 0) {
|
|
30
|
-
throw new Error('`options.position` must be equal or greater than `tokenizer.position`');
|
|
31
|
-
}
|
|
32
|
-
if (normOptions.length === 0) {
|
|
33
|
-
return 0;
|
|
34
|
-
}
|
|
35
|
-
const bytesRead = await this.streamReader.read(uint8Array, normOptions.offset, normOptions.length);
|
|
36
|
-
this.position += bytesRead;
|
|
37
|
-
if ((!options || !options.mayBeLess) && bytesRead < normOptions.length) {
|
|
38
|
-
throw new EndOfStreamError();
|
|
39
|
-
}
|
|
40
|
-
return bytesRead;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Peek (read ahead) buffer from tokenizer
|
|
44
|
-
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
|
45
|
-
* @param options - Read behaviour options
|
|
46
|
-
* @returns Promise with number of bytes peeked
|
|
47
|
-
*/
|
|
48
|
-
async peekBuffer(uint8Array, options) {
|
|
49
|
-
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
50
|
-
let bytesRead = 0;
|
|
51
|
-
if (normOptions.position) {
|
|
52
|
-
const skipBytes = normOptions.position - this.position;
|
|
53
|
-
if (skipBytes > 0) {
|
|
54
|
-
const skipBuffer = new Uint8Array(normOptions.length + skipBytes);
|
|
55
|
-
bytesRead = await this.peekBuffer(skipBuffer, { mayBeLess: normOptions.mayBeLess });
|
|
56
|
-
uint8Array.set(skipBuffer.subarray(skipBytes), normOptions.offset);
|
|
57
|
-
return bytesRead - skipBytes;
|
|
58
|
-
}
|
|
59
|
-
else if (skipBytes < 0) {
|
|
60
|
-
throw new Error('Cannot peek from a negative offset in a stream');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (normOptions.length > 0) {
|
|
64
|
-
try {
|
|
65
|
-
bytesRead = await this.streamReader.peek(uint8Array, normOptions.offset, normOptions.length);
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
if (options && options.mayBeLess && err instanceof EndOfStreamError) {
|
|
69
|
-
return 0;
|
|
70
|
-
}
|
|
71
|
-
throw err;
|
|
72
|
-
}
|
|
73
|
-
if ((!normOptions.mayBeLess) && bytesRead < normOptions.length) {
|
|
74
|
-
throw new EndOfStreamError();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return bytesRead;
|
|
78
|
-
}
|
|
79
|
-
async ignore(length) {
|
|
80
|
-
// debug(`ignore ${this.position}...${this.position + length - 1}`);
|
|
81
|
-
const bufSize = Math.min(maxBufferSize, length);
|
|
82
|
-
const buf = new Uint8Array(bufSize);
|
|
83
|
-
let totBytesRead = 0;
|
|
84
|
-
while (totBytesRead < length) {
|
|
85
|
-
const remaining = length - totBytesRead;
|
|
86
|
-
const bytesRead = await this.readBuffer(buf, { length: Math.min(bufSize, remaining) });
|
|
87
|
-
if (bytesRead < 0) {
|
|
88
|
-
return bytesRead;
|
|
89
|
-
}
|
|
90
|
-
totBytesRead += bytesRead;
|
|
91
|
-
}
|
|
92
|
-
return totBytesRead;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
1
|
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
2
|
+
import { EndOfStreamError, StreamReader } from 'peek-readable';
|
|
3
|
+
const maxBufferSize = 256000;
|
|
4
|
+
export class ReadStreamTokenizer extends AbstractTokenizer {
|
|
5
|
+
constructor(stream, fileInfo) {
|
|
6
|
+
super(fileInfo);
|
|
7
|
+
this.streamReader = new StreamReader(stream);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get file information, an HTTP-client may implement this doing a HEAD request
|
|
11
|
+
* @return Promise with file information
|
|
12
|
+
*/
|
|
13
|
+
async getFileInfo() {
|
|
14
|
+
return this.fileInfo;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Read buffer from tokenizer
|
|
18
|
+
* @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
|
|
19
|
+
* @param options - Read behaviour options
|
|
20
|
+
* @returns Promise with number of bytes read
|
|
21
|
+
*/
|
|
22
|
+
async readBuffer(uint8Array, options) {
|
|
23
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
24
|
+
const skipBytes = normOptions.position - this.position;
|
|
25
|
+
if (skipBytes > 0) {
|
|
26
|
+
await this.ignore(skipBytes);
|
|
27
|
+
return this.readBuffer(uint8Array, options);
|
|
28
|
+
}
|
|
29
|
+
else if (skipBytes < 0) {
|
|
30
|
+
throw new Error('`options.position` must be equal or greater than `tokenizer.position`');
|
|
31
|
+
}
|
|
32
|
+
if (normOptions.length === 0) {
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
const bytesRead = await this.streamReader.read(uint8Array, normOptions.offset, normOptions.length);
|
|
36
|
+
this.position += bytesRead;
|
|
37
|
+
if ((!options || !options.mayBeLess) && bytesRead < normOptions.length) {
|
|
38
|
+
throw new EndOfStreamError();
|
|
39
|
+
}
|
|
40
|
+
return bytesRead;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Peek (read ahead) buffer from tokenizer
|
|
44
|
+
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
|
45
|
+
* @param options - Read behaviour options
|
|
46
|
+
* @returns Promise with number of bytes peeked
|
|
47
|
+
*/
|
|
48
|
+
async peekBuffer(uint8Array, options) {
|
|
49
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
50
|
+
let bytesRead = 0;
|
|
51
|
+
if (normOptions.position) {
|
|
52
|
+
const skipBytes = normOptions.position - this.position;
|
|
53
|
+
if (skipBytes > 0) {
|
|
54
|
+
const skipBuffer = new Uint8Array(normOptions.length + skipBytes);
|
|
55
|
+
bytesRead = await this.peekBuffer(skipBuffer, { mayBeLess: normOptions.mayBeLess });
|
|
56
|
+
uint8Array.set(skipBuffer.subarray(skipBytes), normOptions.offset);
|
|
57
|
+
return bytesRead - skipBytes;
|
|
58
|
+
}
|
|
59
|
+
else if (skipBytes < 0) {
|
|
60
|
+
throw new Error('Cannot peek from a negative offset in a stream');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (normOptions.length > 0) {
|
|
64
|
+
try {
|
|
65
|
+
bytesRead = await this.streamReader.peek(uint8Array, normOptions.offset, normOptions.length);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (options && options.mayBeLess && err instanceof EndOfStreamError) {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
if ((!normOptions.mayBeLess) && bytesRead < normOptions.length) {
|
|
74
|
+
throw new EndOfStreamError();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return bytesRead;
|
|
78
|
+
}
|
|
79
|
+
async ignore(length) {
|
|
80
|
+
// debug(`ignore ${this.position}...${this.position + length - 1}`);
|
|
81
|
+
const bufSize = Math.min(maxBufferSize, length);
|
|
82
|
+
const buf = new Uint8Array(bufSize);
|
|
83
|
+
let totBytesRead = 0;
|
|
84
|
+
while (totBytesRead < length) {
|
|
85
|
+
const remaining = length - totBytesRead;
|
|
86
|
+
const bytesRead = await this.readBuffer(buf, { length: Math.min(bufSize, remaining) });
|
|
87
|
+
if (bytesRead < 0) {
|
|
88
|
+
return bytesRead;
|
|
89
|
+
}
|
|
90
|
+
totBytesRead += bytesRead;
|
|
91
|
+
}
|
|
92
|
+
return totBytesRead;
|
|
93
|
+
}
|
|
94
|
+
}
|
package/lib/core.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
|
3
|
-
import { Readable } from 'node:stream';
|
|
4
|
-
import { BufferTokenizer } from './BufferTokenizer.js';
|
|
5
|
-
import { IFileInfo } from './types.js';
|
|
6
|
-
export { EndOfStreamError } from 'peek-readable';
|
|
7
|
-
export { ITokenizer, IFileInfo } from './types.js';
|
|
8
|
-
export { 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 fileInfo - Pass the file information, like size and MIME-type of the corresponding stream.
|
|
14
|
-
* @returns ReadStreamTokenizer
|
|
15
|
-
*/
|
|
16
|
-
export declare function fromStream(stream: Readable, fileInfo?: IFileInfo): ReadStreamTokenizer;
|
|
17
|
-
/**
|
|
18
|
-
* Construct ReadStreamTokenizer from given Buffer.
|
|
19
|
-
* @param uint8Array - Uint8Array to tokenize
|
|
20
|
-
* @param fileInfo - Pass additional file information to the tokenizer
|
|
21
|
-
* @returns BufferTokenizer
|
|
22
|
-
*/
|
|
23
|
-
export declare function fromBuffer(uint8Array: Uint8Array, fileInfo?: IFileInfo): BufferTokenizer;
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
import { BufferTokenizer } from './BufferTokenizer.js';
|
|
5
|
+
import { IFileInfo } from './types.js';
|
|
6
|
+
export { EndOfStreamError } from 'peek-readable';
|
|
7
|
+
export { ITokenizer, IFileInfo } from './types.js';
|
|
8
|
+
export { 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 fileInfo - Pass the file information, like size and MIME-type of the corresponding stream.
|
|
14
|
+
* @returns ReadStreamTokenizer
|
|
15
|
+
*/
|
|
16
|
+
export declare function fromStream(stream: Readable, fileInfo?: IFileInfo): ReadStreamTokenizer;
|
|
17
|
+
/**
|
|
18
|
+
* Construct ReadStreamTokenizer from given Buffer.
|
|
19
|
+
* @param uint8Array - Uint8Array to tokenize
|
|
20
|
+
* @param fileInfo - Pass additional file information to the tokenizer
|
|
21
|
+
* @returns BufferTokenizer
|
|
22
|
+
*/
|
|
23
|
+
export declare function fromBuffer(uint8Array: Uint8Array, fileInfo?: IFileInfo): BufferTokenizer;
|
package/lib/core.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
|
2
|
-
import { BufferTokenizer } from './BufferTokenizer.js';
|
|
3
|
-
export { EndOfStreamError } from 'peek-readable';
|
|
4
|
-
/**
|
|
5
|
-
* Construct ReadStreamTokenizer from given Stream.
|
|
6
|
-
* Will set fileSize, if provided given Stream has set the .path property/
|
|
7
|
-
* @param stream - Read from Node.js Stream.Readable
|
|
8
|
-
* @param fileInfo - Pass the file information, like size and MIME-type of the corresponding stream.
|
|
9
|
-
* @returns ReadStreamTokenizer
|
|
10
|
-
*/
|
|
11
|
-
export function fromStream(stream, fileInfo) {
|
|
12
|
-
fileInfo = fileInfo ? fileInfo : {};
|
|
13
|
-
return new ReadStreamTokenizer(stream, fileInfo);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Construct ReadStreamTokenizer from given Buffer.
|
|
17
|
-
* @param uint8Array - Uint8Array to tokenize
|
|
18
|
-
* @param fileInfo - Pass additional file information to the tokenizer
|
|
19
|
-
* @returns BufferTokenizer
|
|
20
|
-
*/
|
|
21
|
-
export function fromBuffer(uint8Array, fileInfo) {
|
|
22
|
-
return new BufferTokenizer(uint8Array, fileInfo);
|
|
23
|
-
}
|
|
1
|
+
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
|
2
|
+
import { BufferTokenizer } from './BufferTokenizer.js';
|
|
3
|
+
export { EndOfStreamError } from 'peek-readable';
|
|
4
|
+
/**
|
|
5
|
+
* Construct ReadStreamTokenizer from given Stream.
|
|
6
|
+
* Will set fileSize, if provided given Stream has set the .path property/
|
|
7
|
+
* @param stream - Read from Node.js Stream.Readable
|
|
8
|
+
* @param fileInfo - Pass the file information, like size and MIME-type of the corresponding stream.
|
|
9
|
+
* @returns ReadStreamTokenizer
|
|
10
|
+
*/
|
|
11
|
+
export function fromStream(stream, fileInfo) {
|
|
12
|
+
fileInfo = fileInfo ? fileInfo : {};
|
|
13
|
+
return new ReadStreamTokenizer(stream, fileInfo);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Construct ReadStreamTokenizer from given Buffer.
|
|
17
|
+
* @param uint8Array - Uint8Array to tokenize
|
|
18
|
+
* @param fileInfo - Pass additional file information to the tokenizer
|
|
19
|
+
* @returns BufferTokenizer
|
|
20
|
+
*/
|
|
21
|
+
export function fromBuffer(uint8Array, fileInfo) {
|
|
22
|
+
return new BufferTokenizer(uint8Array, fileInfo);
|
|
23
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Readable } from 'node:stream';
|
|
3
|
-
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
|
4
|
-
import * as core from './core.js';
|
|
5
|
-
export { fromFile } from './FileTokenizer.js';
|
|
6
|
-
export { ITokenizer, EndOfStreamError, fromBuffer, IFileInfo } from './core.js';
|
|
7
|
-
export { 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 fileInfo - Pass additional file information to the tokenizer
|
|
13
|
-
* @returns Tokenizer
|
|
14
|
-
*/
|
|
15
|
-
export declare function fromStream(stream: Readable, fileInfo?: core.IFileInfo): Promise<ReadStreamTokenizer>;
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
|
4
|
+
import * as core from './core.js';
|
|
5
|
+
export { fromFile } from './FileTokenizer.js';
|
|
6
|
+
export { ITokenizer, EndOfStreamError, fromBuffer, IFileInfo } from './core.js';
|
|
7
|
+
export { 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 fileInfo - Pass additional file information to the tokenizer
|
|
13
|
+
* @returns Tokenizer
|
|
14
|
+
*/
|
|
15
|
+
export declare function fromStream(stream: Readable, fileInfo?: core.IFileInfo): Promise<ReadStreamTokenizer>;
|
package/lib/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import * as fs from './FsPromise.js';
|
|
2
|
-
import * as core from './core.js';
|
|
3
|
-
export { fromFile } from './FileTokenizer.js';
|
|
4
|
-
export { EndOfStreamError, fromBuffer } 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 fileInfo - Pass additional file information to the tokenizer
|
|
10
|
-
* @returns Tokenizer
|
|
11
|
-
*/
|
|
12
|
-
export async function fromStream(stream, fileInfo) {
|
|
13
|
-
fileInfo = fileInfo ? fileInfo : {};
|
|
14
|
-
if (stream.path) {
|
|
15
|
-
const stat = await fs.stat(stream.path);
|
|
16
|
-
fileInfo.path = stream.path;
|
|
17
|
-
fileInfo.size = stat.size;
|
|
18
|
-
}
|
|
19
|
-
return core.fromStream(stream, fileInfo);
|
|
20
|
-
}
|
|
1
|
+
import * as fs from './FsPromise.js';
|
|
2
|
+
import * as core from './core.js';
|
|
3
|
+
export { fromFile } from './FileTokenizer.js';
|
|
4
|
+
export { EndOfStreamError, fromBuffer } 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 fileInfo - Pass additional file information to the tokenizer
|
|
10
|
+
* @returns Tokenizer
|
|
11
|
+
*/
|
|
12
|
+
export async function fromStream(stream, fileInfo) {
|
|
13
|
+
fileInfo = fileInfo ? fileInfo : {};
|
|
14
|
+
if (stream.path) {
|
|
15
|
+
const stat = await fs.stat(stream.path);
|
|
16
|
+
fileInfo.path = stream.path;
|
|
17
|
+
fileInfo.size = stat.size;
|
|
18
|
+
}
|
|
19
|
+
return core.fromStream(stream, fileInfo);
|
|
20
|
+
}
|