mongo.gridfile.writer.create: Create a mongo.gridfile.writer object

Description Usage Arguments Value See Also Examples

View source: R/gridfs.R

Description

Create a mongo.gridfile.writer object used to buffer many writes to a single GridFS file. Once the mongo.gridfile.writer is created, use mongo.gridfile.writer.write() to write data to the buffered GridFS file and mongo.gridfile.writer.finish() when done.

Usage

1
mongo.gridfile.writer.create(gridfs, remotename, contenttype = "")

Arguments

gridfs

A (mongo.gridfs) object.

remotename

(string) The name the file will be known as within the GridFS.

contenttype

(string) Optional MIME content type.

Value

(mongo.gridfile.writer) The object to be used for writing to the GridFS file.

See Also

mongo.gridfs,
mongo.gridfs.create,
mongo.gridfile.writer.write,
mongo.gridfile.writer.finish.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    gridfs <- mongo.gridfs.create(mongo, "grid")

    gfw <- mongo.gridfile.writer.create(gridfs, "test.dat")

    # store 4 bytes
    mongo.gridfile.writer.write(gfw, charToRaw("test"))

    # store string & LF plus 0-byte terminator
    buf <- writeBin("Test\n", as.raw(1))
    mongo.gridfile.writer.write(gfw, buf)

    # store PI as a float
    buf <- writeBin(3.1415926, as.raw(1), size=4, endian="little")
    mongo.gridfile.writer.write(gfw, buf)

    mongo.gridfile.writer.finish(gfw)
    mongo.gridfs.destroy(gridfs)
}

jonkatz2/rmongodb documentation built on May 19, 2019, 7:30 p.m.