MCPcopy
hub / github.com/mongodb/node-mongodb-native / openDownloadStreamByName

Method openDownloadStreamByName

src/gridfs/index.ts:203–224  ·  view source on GitHub ↗

* Returns a readable stream (GridFSBucketReadStream) for streaming the * file with the given name from GridFS. If there are multiple files with * the same name, this will stream the most recent file with the given name * (as determined by the `uploadDate` field). You can set the `revision`

(
    filename: string,
    options?: GridFSBucketReadStreamOptionsWithRevision
  )

Source from the content-addressed store, hash-verified

201 * option to change this behavior.
202 */
203 openDownloadStreamByName(
204 filename: string,
205 options?: GridFSBucketReadStreamOptionsWithRevision
206 ): GridFSBucketReadStream {
207 let sort: Sort = { uploadDate: -1 };
208 let skip = undefined;
209 if (options && options.revision != null) {
210 if (options.revision >= 0) {
211 sort = { uploadDate: 1 };
212 skip = options.revision;
213 } else {
214 skip = -options.revision - 1;
215 }
216 }
217 return new GridFSBucketReadStream(
218 this.s._chunksCollection,
219 this.s._filesCollection,
220 this.s.options.readPreference,
221 { filename },
222 { timeoutMS: this.s.options.timeoutMS, ...options, sort, skip }
223 );
224 }
225
226 /**
227 * Renames the file with the given _id to the given string

Callers 6

testFunction · 0.95
operations.tsFile · 0.80
node_csot.test.tsFile · 0.80
sort.test-d.tsFile · 0.80
main.test.tsFile · 0.80

Calls

no outgoing calls

Tested by 1

testFunction · 0.76