///
///
import { Readable } from 'stream';
import type { Document, ObjectId } from '../bson';
import type { Collection } from '../collection';
import type { FindCursor } from '../cursor/find_cursor';
import type { ReadPreference } from '../read_preference';
import type { Sort } from '../sort';
import type { Callback } from '../utils';
import type { GridFSChunk } from './upload';
/** @public */
export interface GridFSBucketReadStreamOptions {
sort?: Sort;
skip?: number;
/** 0-based offset in bytes to start streaming from */
start?: number;
/** 0-based offset in bytes to stop streaming before */
end?: number;
}
/** @public */
export interface GridFSBucketReadStreamOptionsWithRevision extends GridFSBucketReadStreamOptions {
/** The revision number relative to the oldest file with the given filename. 0
* gets you the oldest file, 1 gets you the 2nd oldest, -1 gets you the
* newest. */
revision?: number;
}
/** @public */
export interface GridFSFile {
_id: ObjectId;
length: number;
chunkSize: number;
filename: string;
contentType?: string;
aliases?: string[];
metadata?: Document;
uploadDate: Date;
}
/** @internal */
export interface GridFSBucketReadStreamPrivate {
bytesRead: number;
bytesToTrim: number;
bytesToSkip: number;
chunks: Collection;
cursor?: FindCursor;
expected: number;
files: Collection;
filter: Document;
init: boolean;
expectedEnd: number;
file?: GridFSFile;
options: {
sort?: Sort;
skip?: number;
start: number;
end: number;
};
readPreference?: ReadPreference;
}
/**
* A readable stream that enables you to read buffers from GridFS.
*
* Do not instantiate this class directly. Use `openDownloadStream()` instead.
* @public
*/
export declare class GridFSBucketReadStream extends Readable implements NodeJS.ReadableStream {
/** @internal */
s: GridFSBucketReadStreamPrivate;
/**
* An error occurred
* @event
*/
static readonly ERROR: "error";
/**
* Fires when the stream loaded the file document corresponding to the provided id.
* @event
*/
static readonly FILE: "file";
/**
* Emitted when a chunk of data is available to be consumed.
* @event
*/
static readonly DATA: "data";
/**
* Fired when the stream is exhausted (no more data events).
* @event
*/
static readonly END: "end";
/**
* Fired when the stream is exhausted and the underlying cursor is killed
* @event
*/
static readonly CLOSE: "close";
/** @internal
* @param chunks - Handle for chunks collection
* @param files - Handle for files collection
* @param readPreference - The read preference to use
* @param filter - The filter to use to find the file document
*/
constructor(chunks: Collection, files: Collection, readPreference: ReadPreference | undefined, filter: Document, options?: GridFSBucketReadStreamOptions);
/**
* Reads from the cursor and pushes to the stream.
* Private Impl, do not call directly
* @internal
*/
_read(): void;
/**
* Sets the 0-based offset in bytes to start streaming from. Throws
* an error if this stream has entered flowing mode
* (e.g. if you've already called `on('data')`)
*
* @param start - 0-based offset in bytes to start streaming from
*/
start(start?: number): this;
/**
* Sets the 0-based offset in bytes to start streaming from. Throws
* an error if this stream has entered flowing mode
* (e.g. if you've already called `on('data')`)
*
* @param end - Offset in bytes to stop reading at
*/
end(end?: number): this;
/**
* Marks this stream as aborted (will never push another `data` event)
* and kills the underlying cursor. Will emit the 'end' event, and then
* the 'close' event once the cursor is successfully killed.
*
* @param callback - called when the cursor is successfully closed or an error occurred.
*/
abort(callback?: Callback): void;
}
//# sourceMappingURL=download.d.ts.map