///
///
///
import { Writable } from 'stream';
import type { Document } from '../bson';
import { ObjectId } from '../bson';
import type { Collection } from '../collection';
import { Callback } from '../utils';
import type { WriteConcernOptions } from '../write_concern';
import { WriteConcern } from './../write_concern';
import type { GridFSFile } from './download';
import type { GridFSBucket } from './index';
/** @public */
export interface GridFSChunk {
_id: ObjectId;
files_id: ObjectId;
n: number;
data: Buffer | Uint8Array;
}
/** @public */
export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
/** Overwrite this bucket's chunkSizeBytes for this file */
chunkSizeBytes?: number;
/** Custom file id for the GridFS file. */
id?: ObjectId;
/** Object to store in the file document's `metadata` field */
metadata?: Document;
/** String to store in the file document's `contentType` field */
contentType?: string;
/** Array of strings to store in the file document's `aliases` field */
aliases?: string[];
}
/**
* A writable stream that enables you to write buffers to GridFS.
*
* Do not instantiate this class directly. Use `openUploadStream()` instead.
* @public
*/
export declare class GridFSBucketWriteStream extends Writable implements NodeJS.WritableStream {
bucket: GridFSBucket;
chunks: Collection;
filename: string;
files: Collection;
options: GridFSBucketWriteStreamOptions;
done: boolean;
id: ObjectId;
chunkSizeBytes: number;
bufToStore: Buffer;
length: number;
n: number;
pos: number;
state: {
streamEnd: boolean;
outstandingRequests: number;
errored: boolean;
aborted: boolean;
};
writeConcern?: WriteConcern;
/** @event */
static readonly CLOSE = "close";
/** @event */
static readonly ERROR = "error";
/**
* `end()` was called and the write stream successfully wrote the file metadata and all the chunks to MongoDB.
* @event
*/
static readonly FINISH = "finish";
/** @internal
* @param bucket - Handle for this stream's corresponding bucket
* @param filename - The value of the 'filename' key in the files doc
* @param options - Optional settings.
*/
constructor(bucket: GridFSBucket, filename: string, options?: GridFSBucketWriteStreamOptions);
/**
* Write a buffer to the stream.
*
* @param chunk - Buffer to write
* @param encodingOrCallback - Optional encoding for the buffer
* @param callback - Function to call when the chunk was added to the buffer, or if the entire chunk was persisted to MongoDB if this chunk caused a flush.
* @returns False if this write required flushing a chunk to MongoDB. True otherwise.
*/
write(chunk: Buffer | string): boolean;
write(chunk: Buffer | string, callback: Callback): boolean;
write(chunk: Buffer | string, encoding: BufferEncoding | undefined): boolean;
write(chunk: Buffer | string, encoding: BufferEncoding | undefined, callback: Callback): boolean;
/**
* Places this write stream into an aborted state (all future writes fail)
* and deletes all chunks that have already been written.
*
* @param callback - called when chunks are successfully removed or error occurred
*/
abort(): Promise;
abort(callback: Callback): void;
/**
* Tells the stream that no more data will be coming in. The stream will
* persist the remaining data to MongoDB, write the files document, and
* then emit a 'finish' event.
*
* @param chunk - Buffer to write
* @param encoding - Optional encoding for the buffer
* @param callback - Function to call when all files and chunks have been persisted to MongoDB
*/
end(): this;
end(chunk: Buffer): this;
end(callback: Callback): this;
end(chunk: Buffer, callback: Callback): this;
end(chunk: Buffer, encoding: BufferEncoding): this;
end(chunk: Buffer, encoding: BufferEncoding | undefined, callback: Callback): this;
}
//# sourceMappingURL=upload.d.ts.map