src/anonimongo/gridfs

Search:
Group by:
Source   Edit  

Types

GridStream[TheSocket] {..} = ref object of RootObj
  
Source   Edit  

Procs

proc availableFiles(g: GridFS[AsyncSocket]; query = bson()): Future[int] {.
    ...stackTrace: false, raises: [Exception, ValueError],
    tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Source   Edit  
proc availableFiles(g: GridFS[Socket]; query = bson()): int {....raises: [
    ValueError, Exception, KeyError, MongoError, IOError, OSError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Source   Edit  
proc close(gs: GridStream)
Source   Edit  
proc createBucket(c: Collection[AsyncSocket]; name = "fs";
                  chunkSize = defaultChunkSize): Future[GridFS[AsyncSocket]] {.
    ...stackTrace: false, raises: [Exception, ValueError],
    tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
CollectionAsyncSocket version to create bucket. Offload the actual operation to gridfs.createBucket(database). Source   Edit  
proc createBucket(c: Collection[Socket]; name = "fs";
                  chunkSize = defaultChunkSize): GridFS[Socket] {....raises: [
    ValueError, Exception, KeyError, MongoError, IOError, OSError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
CollectionAsyncSocket version to create bucket. Offload the actual operation to gridfs.createBucket(database). Source   Edit  
proc createBucket(db: Database[AsyncSocket]; name = "fs";
                  chunkSize = defaultChunkSize): Future[GridFS[AsyncSocket]] {.
    ...stackTrace: false, raises: [Exception, ValueError],
    tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
By default it's using string "fs" for bucket name with default chunk size for file is 255 KB. The chunk size can be override for each uploadFile but by default will using the defined gridfs chunk size. As mentioned in Mongo spec, each collection has its own indexes i.e <bucketname>.files has index { filename: 1, uploadData: 1 } <bucketname>.chunks has index { files_id: 1, n: 1 }. Source   Edit  
proc createBucket(db: Database[Socket]; name = "fs";
                  chunkSize = defaultChunkSize): GridFS[Socket] {....raises: [
    ValueError, Exception, KeyError, MongoError, IOError, OSError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
By default it's using string "fs" for bucket name with default chunk size for file is 255 KB. The chunk size can be override for each uploadFile but by default will using the defined gridfs chunk size. As mentioned in Mongo spec, each collection has its own indexes i.e <bucketname>.files has index { filename: 1, uploadData: 1 } <bucketname>.chunks has index { files_id: 1, n: 1 }. Source   Edit  
proc downloadAs(g: GridFS[AsyncSocket]; source, target: string): Future[
    WriteResult] {....stackTrace: false, raises: [Exception, ValueError],
                   tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect],
                   forbids: [].}
To download file as different file name. Source   Edit  
proc downloadAs(g: GridFS[Socket]; source, target: string): WriteResult {....raises: [
    OSError, ValueError, Exception, KeyError, MongoError, IOError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
To download file as different file name. Source   Edit  
proc downloadFile(bucket: GridFS[AsyncSocket]; filename: string): Future[
    WriteResult] {....stackTrace: false, raises: [Exception, ValueError],
                   tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect],
                   forbids: [].}
Higher version for downloadFile. Ensure the destination file path has writing permission Source   Edit  
proc downloadFile(bucket: GridFS[Socket]; filename: string): WriteResult {....raises: [
    OSError, ValueError, Exception, KeyError, MongoError, IOError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Higher version for downloadFile. Ensure the destination file path has writing permission Source   Edit  
proc downloadFile(g: GridFS[AsyncSocket]; f: AsyncFile; filename = ""): Future[
    WriteResult] {....stackTrace: false, raises: [Exception, ValueError],
                   tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect],
                   forbids: [].}
Download given filename and write it to f asyncfile. This only download the latest uploaded file in the same name. Source   Edit  
proc downloadFile(g: GridFS[Socket]; f: AsyncFile; filename = ""): WriteResult {....raises: [
    ValueError, Exception, KeyError, MongoError, IOError, OSError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Download given filename and write it to f asyncfile. This only download the latest uploaded file in the same name. Source   Edit  
proc drop(g: GridFS[AsyncSocket]): Future[WriteResult] {....stackTrace: false,
    raises: [Exception, ValueError],
    tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Drop the current bucket name. Source   Edit  
proc drop(g: GridFS[Socket]): WriteResult {....raises: [KeyError, ValueError,
    MongoError, IOError, OSError, Exception, SnappyError, ZippyError, SslError,
    TimeoutError], tags: [WriteIOEffect, ReadIOEffect, RootEffect, TimeEffect],
    forbids: [].}
Drop the current bucket name. Source   Edit  
func fileSize(gs: GridStream): int64
Source   Edit  
proc getBucket(c: Collection[AsyncSocket]; name = "fs"): Future[
    GridFS[AsyncSocket]] {....stackTrace: false, raises: [Exception, ValueError], tags: [
    RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Source   Edit  
proc getBucket(c: Collection[Socket]; name = "fs"): GridFS[Socket] {....raises: [
    ValueError, Exception, KeyError, MongoError, IOError, OSError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Source   Edit  
proc getBucket(db: Database[AsyncSocket]; name = "fs"): Future[
    GridFS[AsyncSocket]] {....stackTrace: false, raises: [Exception, ValueError], tags: [
    RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Get bucket from existing database. If the bucket is not available, Mongo will implicitly create the files and chunks collections but without the necessary indexes. Source   Edit  
proc getBucket(db: Database[Socket]; name = "fs"): GridFS[Socket] {....raises: [
    ValueError, Exception, KeyError, MongoError, IOError, OSError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Get bucket from existing database. If the bucket is not available, Mongo will implicitly create the files and chunks collections but without the necessary indexes. Source   Edit  
func getPosition(gs: GridStream): int64
Source   Edit  
proc getStream(g: GridFS[AsyncSocket]; matcher: BsonBase; sort = bson();
               buffered = false): Future[GridStream[AsyncSocket]] {.
    ...stackTrace: false, raises: [Exception, ValueError],
    tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Source   Edit  
proc getStream(g: GridFS[Socket]; matcher: BsonBase; sort = bson();
               buffered = false): GridStream[Socket] {....raises: [ValueError,
    Exception, KeyError, MongoError, IOError, OSError, SnappyError, ZippyError,
    SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Source   Edit  
func kilobytes(n: Positive): int {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc listFileNames(g: GridFS[AsyncSocket]; matcher = "all".toBson; sort = bson()): Future[
    seq[string]] {....stackTrace: false, raises: [Exception, ValueError],
                   tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect],
                   forbids: [].}
Retrieve available list filenames given matcher Bson. By default the matcher is BsonString "all" which return all available names. Sort to choose the order which criteria it's should be first/last. The matcher is elaborated explained removeFile as it's using the same mechanism. Source   Edit  
proc listFileNames(g: GridFS[Socket]; matcher = "all".toBson; sort = bson()): seq[
    string] {....raises: [ValueError, Exception, KeyError, MongoError, IOError,
                       OSError, SnappyError, ZippyError, SslError, TimeoutError],
              tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect],
              forbids: [].}
Retrieve available list filenames given matcher Bson. By default the matcher is BsonString "all" which return all available names. Sort to choose the order which criteria it's should be first/last. The matcher is elaborated explained removeFile as it's using the same mechanism. Source   Edit  
func megabytes(n: Positive): int {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc read(gs: GridStream[AsyncSocket]; length = 0'i64): Future[string] {.
    ...stackTrace: false, raises: [Exception, ValueError],
    tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Source   Edit  
proc read(gs: GridStream[Socket]; length = 0'i64): string {....raises: [ValueError,
    Exception, KeyError, MongoError, IOError, OSError, SnappyError, ZippyError,
    SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Source   Edit  
proc readAll(gs: GridStream[AsyncSocket]): Future[string] {....stackTrace: false,
    raises: [Exception, ValueError],
    tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Source   Edit  
proc readAll(gs: GridStream[Socket]): string {....raises: [ValueError, Exception,
    KeyError, MongoError, IOError, OSError, SnappyError, ZippyError, SslError,
    TimeoutError], tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect],
    forbids: [].}
Source   Edit  
proc removeFile(g: GridFS[AsyncSocket]; matcher = "all".toBson; one = false): Future[
    WriteResult] {....stackTrace: false, raises: [Exception, ValueError],
                   tags: [RootEffect, TimeEffect, WriteIOEffect, ReadIOEffect],
                   forbids: [].}
Remove available files that match with matcher. By default the matcher is BsonString "all" which remove all files. If it's not "all" and BsonString, it's matched for the filename and for specific finding, matcher can use the regex string e.g.
matcher = bson({
  filename: { "regex": """_\d\.mkv$""" }
})

which looking for any filename that match the pattern i.e.

  • "any_filename_but_aslong_have_1.mkv"
  • "this is ok too_2.mkv"
  • "also this is ok_3.mkv"

For example removing all mkv files, the matcher would be

matcher = bson({ metadata: { ext: "mkv" }})
Source   Edit  
proc removeFile(g: GridFS[Socket]; matcher = "all".toBson; one = false): WriteResult {....raises: [
    ValueError, Exception, KeyError, MongoError, IOError, OSError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Remove available files that match with matcher. By default the matcher is BsonString "all" which remove all files. If it's not "all" and BsonString, it's matched for the filename and for specific finding, matcher can use the regex string e.g.
matcher = bson({
  filename: { "regex": """_\d\.mkv$""" }
})

which looking for any filename that match the pattern i.e.

  • "any_filename_but_aslong_have_1.mkv"
  • "this is ok too_2.mkv"
  • "also this is ok_3.mkv"

For example removing all mkv files, the matcher would be

matcher = bson({ metadata: { ext: "mkv" }})
Source   Edit  
proc setPosition(gs: GridStream[AsyncSocket]; pos: int64; chunkn = -1): owned(
    Future[void]) {....stackTrace: false, raises: [Exception], tags: [RootEffect,
    TimeEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Source   Edit  
proc setPosition(gs: GridStream[Socket]; pos: int64; chunkn = -1) {....raises: [
    ValueError, Exception, KeyError, MongoError, IOError, OSError, SnappyError,
    ZippyError, SslError, TimeoutError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Source   Edit  
proc uploadFile(g: GridFS[AsyncSocket]; f: AsyncFile; filename = "";
                chunk = 0'i32; metadata = bson()): Future[WriteResult] {.
    ...stackTrace: false, raises: [Exception, ValueError],
    tags: [TimeEffect, RootEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Source   Edit  
proc uploadFile(g: GridFS[AsyncSocket]; filename: string; chunk = 0'i32;
                metadata = bson()): Future[WriteResult] {....stackTrace: false,
    raises: [Exception, ValueError],
    tags: [TimeEffect, RootEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
A higher uploadFile which directly open and close file from filename. Source   Edit  
proc uploadFile(g: GridFS[Socket]; f: AsyncFile; filename = ""; chunk = 0'i32;
                metadata = bson()): WriteResult {....raises: [OSError, KeyError,
    ValueError, Exception, MongoError, IOError, SnappyError, ZippyError,
    SslError, TimeoutError],
    tags: [TimeEffect, RootEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
Source   Edit  
proc uploadFile(g: GridFS[Socket]; filename: string; chunk = 0'i32;
                metadata = bson()): WriteResult {....raises: [OSError, KeyError,
    ValueError, Exception, MongoError, IOError, SnappyError, ZippyError,
    SslError, TimeoutError],
    tags: [TimeEffect, RootEffect, WriteIOEffect, ReadIOEffect], forbids: [].}
A higher uploadFile which directly open and close file from filename. Source   Edit