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); }