Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
22 lines
852 B
Plaintext
22 lines
852 B
Plaintext
import { stat as fsStat } from 'node:fs/promises';
|
|
import { fromStream as coreFromStream } from './core.js';
|
|
export { fromFile } from './FileTokenizer.js';
|
|
export * from './core.js';
|
|
/**
|
|
* Construct ReadStreamTokenizer from given Stream.
|
|
* Will set fileSize, if provided given Stream has set the .path property.
|
|
* @param stream - Node.js Stream.Readable
|
|
* @param options - Pass additional file information to the tokenizer
|
|
* @returns Tokenizer
|
|
*/
|
|
export async function fromStream(stream, options) {
|
|
const augmentedOptions = options ?? {};
|
|
augmentedOptions.fileInfo = augmentedOptions.fileInfo ?? {};
|
|
if (stream.path) {
|
|
const stat = await fsStat(stream.path);
|
|
augmentedOptions.fileInfo.path = stream.path;
|
|
augmentedOptions.fileInfo.size = stat.size;
|
|
}
|
|
return coreFromStream(stream, augmentedOptions);
|
|
}
|