|
1 | 1 | // TODO(RUST-1395) Remove these allows.
|
2 |
| -#![allow(dead_code, unused_variables)] |
| 2 | +#![allow(dead_code, unused_variables, missing_docs)] |
3 | 3 |
|
4 | 4 | mod download;
|
5 | 5 | pub mod options;
|
6 | 6 | mod upload;
|
7 | 7 |
|
8 |
| -use core::task::{Context, Poll}; |
9 |
| -use std::{ |
10 |
| - pin::Pin, |
11 |
| - sync::{atomic::AtomicBool, Arc}, |
12 |
| -}; |
| 8 | +use std::sync::{atomic::AtomicBool, Arc}; |
13 | 9 |
|
14 | 10 | use serde::{Deserialize, Serialize};
|
15 | 11 | use serde_with::skip_serializing_none;
|
16 | 12 |
|
17 | 13 | use crate::{
|
18 | 14 | bson::{doc, oid::ObjectId, Bson, DateTime, Document, RawBinaryRef},
|
19 | 15 | cursor::Cursor,
|
20 |
| - error::{ErrorKind, GridFsErrorKind, GridFsFileIdentifier, Result}, |
| 16 | + error::{Error, ErrorKind, GridFsErrorKind, GridFsFileIdentifier, Result}, |
21 | 17 | options::{CollectionOptions, FindOptions, ReadConcern, SelectionCriteria, WriteConcern},
|
22 | 18 | Collection,
|
23 | 19 | Database,
|
24 | 20 | };
|
25 | 21 |
|
26 |
| -use options::*; |
| 22 | +pub use download::GridFsDownloadStream; |
| 23 | +pub use options::*; |
| 24 | +pub use upload::GridFsUploadStream; |
27 | 25 |
|
28 | 26 | pub const DEFAULT_BUCKET_NAME: &str = "fs";
|
29 | 27 | pub const DEFAULT_CHUNK_SIZE_BYTES: u32 = 255 * 1024;
|
30 | 28 |
|
31 | 29 | // Contained in a "chunks" collection for each user file
|
32 | 30 | #[derive(Debug, Deserialize, Serialize)]
|
33 |
| -struct Chunk<'a> { |
| 31 | +pub(crate) struct Chunk<'a> { |
34 | 32 | #[serde(rename = "_id")]
|
35 | 33 | id: ObjectId,
|
36 | 34 | files_id: Bson,
|
@@ -97,70 +95,6 @@ pub struct GridFsBucket {
|
97 | 95 | inner: Arc<GridFsBucketInner>,
|
98 | 96 | }
|
99 | 97 |
|
100 |
| -// TODO: RUST-1395 Add documentation and example code for this struct. |
101 |
| -pub struct GridFsUploadStream { |
102 |
| - files_id: Bson, |
103 |
| -} |
104 |
| - |
105 |
| -impl GridFsUploadStream { |
106 |
| - /// Gets the file `id` for the stream. |
107 |
| - pub fn files_id(&self) -> &Bson { |
108 |
| - &self.files_id |
109 |
| - } |
110 |
| - |
111 |
| - /// Consumes the stream and uploads data in the stream to the server. |
112 |
| - pub async fn finish(self) { |
113 |
| - todo!() |
114 |
| - } |
115 |
| - |
116 |
| - /// Aborts the upload and discards the upload stream. |
117 |
| - pub async fn abort(self) { |
118 |
| - todo!() |
119 |
| - } |
120 |
| -} |
121 |
| - |
122 |
| -impl tokio::io::AsyncWrite for GridFsUploadStream { |
123 |
| - fn poll_write( |
124 |
| - self: Pin<&mut Self>, |
125 |
| - cx: &mut Context<'_>, |
126 |
| - buf: &[u8], |
127 |
| - ) -> Poll<tokio::io::Result<usize>> { |
128 |
| - todo!() |
129 |
| - } |
130 |
| - |
131 |
| - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<tokio::io::Result<()>> { |
132 |
| - todo!() |
133 |
| - } |
134 |
| - |
135 |
| - fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<tokio::io::Result<()>> { |
136 |
| - todo!() |
137 |
| - } |
138 |
| -} |
139 |
| - |
140 |
| -impl futures_util::AsyncWrite for GridFsUploadStream { |
141 |
| - fn poll_write( |
142 |
| - self: Pin<&mut Self>, |
143 |
| - cx: &mut Context<'_>, |
144 |
| - buf: &[u8], |
145 |
| - ) -> Poll<core::result::Result<usize, futures_util::io::Error>> { |
146 |
| - todo!() |
147 |
| - } |
148 |
| - |
149 |
| - fn poll_flush( |
150 |
| - self: Pin<&mut Self>, |
151 |
| - cx: &mut Context<'_>, |
152 |
| - ) -> Poll<core::result::Result<(), futures_util::io::Error>> { |
153 |
| - todo!() |
154 |
| - } |
155 |
| - |
156 |
| - fn poll_close( |
157 |
| - self: Pin<&mut Self>, |
158 |
| - cx: &mut Context<'_>, |
159 |
| - ) -> Poll<core::result::Result<(), futures_util::io::Error>> { |
160 |
| - todo!() |
161 |
| - } |
162 |
| -} |
163 |
| - |
164 | 98 | impl GridFsBucket {
|
165 | 99 | pub(crate) fn new(db: Database, mut options: GridFsBucketOptions) -> GridFsBucket {
|
166 | 100 | if options.read_concern.is_none() {
|
@@ -232,41 +166,15 @@ impl GridFsBucket {
|
232 | 166 | }
|
233 | 167 |
|
234 | 168 | /// Gets a handle to the files collection for the [`GridFsBucket`].
|
235 |
| - fn files(&self) -> &Collection<FilesCollectionDocument> { |
| 169 | + pub(crate) fn files(&self) -> &Collection<FilesCollectionDocument> { |
236 | 170 | &self.inner.files
|
237 | 171 | }
|
238 | 172 |
|
239 | 173 | /// Gets a handle to the chunks collection for the [`GridFsBucket`].
|
240 |
| - fn chunks(&self) -> &Collection<Chunk<'static>> { |
| 174 | + pub(crate) fn chunks(&self) -> &Collection<Chunk<'static>> { |
241 | 175 | &self.inner.chunks
|
242 | 176 | }
|
243 | 177 |
|
244 |
| - /// Opens a [`GridFsUploadStream`] that the application can write the contents of the file to. |
245 |
| - /// The application provides a custom file id. |
246 |
| - /// |
247 |
| - /// Returns a [`GridFsUploadStream`] to which the application will write the contents. |
248 |
| - pub async fn open_upload_stream_with_id( |
249 |
| - &self, |
250 |
| - id: Bson, |
251 |
| - filename: String, |
252 |
| - options: impl Into<Option<GridFsUploadOptions>>, |
253 |
| - ) -> Result<GridFsUploadStream> { |
254 |
| - todo!() |
255 |
| - } |
256 |
| - |
257 |
| - /// Opens a [`GridFsUploadStream`] that the application can write the contents of the file to. |
258 |
| - /// The driver generates a unique [`Bson::ObjectId`] for the file id. |
259 |
| - /// |
260 |
| - /// Returns a [`GridFsUploadStream`] to which the application will write the contents. |
261 |
| - pub async fn open_upload_stream( |
262 |
| - &self, |
263 |
| - filename: String, |
264 |
| - options: impl Into<Option<GridFsUploadOptions>>, |
265 |
| - ) -> Result<GridFsUploadStream> { |
266 |
| - self.open_upload_stream_with_id(Bson::ObjectId(ObjectId::new()), filename, options) |
267 |
| - .await |
268 |
| - } |
269 |
| - |
270 | 178 | /// Deletes the [`FilesCollectionDocument`] with the given `id `and its associated chunks from
|
271 | 179 | /// this bucket.
|
272 | 180 | pub async fn delete(&self, id: Bson) -> Result<()> {
|
@@ -322,3 +230,9 @@ impl GridFsBucket {
|
322 | 230 | Ok(())
|
323 | 231 | }
|
324 | 232 | }
|
| 233 | + |
| 234 | +impl Error { |
| 235 | + fn into_futures_io_error(self) -> futures_io::Error { |
| 236 | + futures_io::Error::new(futures_io::ErrorKind::Other, self) |
| 237 | + } |
| 238 | +} |
0 commit comments