/* Copyright 2016-present MongoDB Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.IO; using System.Threading; using System.Threading.Tasks; using MongoDB.Bson; namespace MongoDB.Driver.GridFS { /// /// Represents a GridFS system bucket. /// /// The type of the file identifier. public interface IGridFSBucket { // properties /// /// Gets the database where the GridFS files are stored. /// /// /// The database. /// IMongoDatabase Database { get; } /// /// Gets the options. /// /// /// The options. /// ImmutableGridFSBucketOptions Options { get; } // methods /// /// Deletes a file from GridFS. /// /// The file id. /// The cancellation token. void Delete(TFileId id, CancellationToken cancellationToken = default(CancellationToken)); /// /// Deletes a file from GridFS. /// /// The file id. /// The cancellation token. /// A Task. Task DeleteAsync(TFileId id, CancellationToken cancellationToken = default(CancellationToken)); /// /// Downloads a file stored in GridFS and returns it as a byte array. /// /// The file id. /// The options. /// The cancellation token. /// The contents of the file stored in GridFS. byte[] DownloadAsBytes(TFileId id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Downloads a file stored in GridFS and returns it as a byte array. /// /// The file id. /// The options. /// The cancellation token. /// A Task whose result is a byte array containing the contents of the file stored in GridFS. Task DownloadAsBytesAsync(TFileId id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Downloads a file stored in GridFS and returns it as a byte array. /// /// The filename. /// The options. /// The cancellation token. /// A byte array containing the contents of the file stored in GridFS. byte[] DownloadAsBytesByName(string filename, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Downloads a file stored in GridFS and returns it as a byte array. /// /// The filename. /// The options. /// The cancellation token. /// A Task whose result is a byte array containing the contents of the file stored in GridFS. Task DownloadAsBytesByNameAsync(string filename, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Downloads a file stored in GridFS and writes the contents to a stream. /// /// The file id. /// The destination. /// The options. /// The cancellation token. void DownloadToStream(TFileId id, Stream destination, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Downloads a file stored in GridFS and writes the contents to a stream. /// /// The file id. /// The destination. /// The options. /// The cancellation token. /// A Task. Task DownloadToStreamAsync(TFileId id, Stream destination, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Downloads a file stored in GridFS and writes the contents to a stream. /// /// The filename. /// The destination. /// The options. /// The cancellation token. void DownloadToStreamByName(string filename, Stream destination, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Downloads a file stored in GridFS and writes the contents to a stream. /// /// The filename. /// The destination. /// The options. /// The cancellation token. /// A Task. Task DownloadToStreamByNameAsync(string filename, Stream destination, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Drops the files and chunks collections associated with this GridFS bucket. /// /// The cancellation token. void Drop(CancellationToken cancellationToken = default(CancellationToken)); /// /// Drops the files and chunks collections associated with this GridFS bucket. /// /// The cancellation token. /// A Task. Task DropAsync(CancellationToken cancellationToken = default(CancellationToken)); /// /// Finds matching entries from the files collection. /// /// The filter. /// The options. /// The cancellation token. /// A cursor of files collection documents. IAsyncCursor> Find(FilterDefinition> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Finds matching entries from the files collection. /// /// The filter. /// The options. /// The cancellation token. /// A Task whose result is a cursor of files collection documents. Task>> FindAsync(FilterDefinition> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Opens a Stream that can be used by the application to read data from a GridFS file. /// /// The file id. /// The options. /// The cancellation token. /// A Stream. GridFSDownloadStream OpenDownloadStream(TFileId id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Opens a Stream that can be used by the application to read data from a GridFS file. /// /// The file id. /// The options. /// The cancellation token. /// A Task whose result is a Stream. Task> OpenDownloadStreamAsync(TFileId id, GridFSDownloadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Opens a Stream that can be used by the application to read data from a GridFS file. /// /// The filename. /// The options. /// The cancellation token. /// A Stream. GridFSDownloadStream OpenDownloadStreamByName(string filename, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Opens a Stream that can be used by the application to read data from a GridFS file. /// /// The filename. /// The options. /// The cancellation token. /// A Task whose result is a Stream. Task> OpenDownloadStreamByNameAsync(string filename, GridFSDownloadByNameOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Opens a Stream that can be used by the application to write data to a GridFS file. /// /// The file id. /// The filename. /// The options. /// The cancellation token. /// A Stream. GridFSUploadStream OpenUploadStream(TFileId id, string filename, GridFSUploadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Opens a Stream that can be used by the application to write data to a GridFS file. /// /// The file id. /// The filename. /// The options. /// The cancellation token. /// A Task whose result is a Stream. Task> OpenUploadStreamAsync(TFileId id, string filename, GridFSUploadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Renames a GridFS file. /// /// The file id. /// The new filename. /// The cancellation token. void Rename(TFileId id, string newFilename, CancellationToken cancellationToken = default(CancellationToken)); /// /// Renames a GridFS file. /// /// The file id. /// The new filename. /// The cancellation token. /// A Task. Task RenameAsync(TFileId id, string newFilename, CancellationToken cancellationToken = default(CancellationToken)); /// /// Uploads a file (or a new revision of a file) to GridFS. /// /// The file id. /// The filename. /// The source. /// The options. /// The cancellation token. void UploadFromBytes(TFileId id, string filename, byte[] source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Uploads a file (or a new revision of a file) to GridFS. /// /// The file id. /// The filename. /// The source. /// The options. /// The cancellation token. /// A Task. Task UploadFromBytesAsync(TFileId id, string filename, byte[] source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Uploads a file (or a new revision of a file) to GridFS. /// /// The file id. /// The filename. /// The source. /// The options. /// The cancellation token. /// The id of the new file. void UploadFromStream(TFileId id, string filename, Stream source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); /// /// Uploads a file (or a new revision of a file) to GridFS. /// /// The file id. /// The filename. /// The source. /// The options. /// The cancellation token. /// A Task. Task UploadFromStreamAsync(TFileId id, string filename, Stream source, GridFSUploadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)); } }