rmongodb (version 1.8.0)

mongo.gridfile.writer: The mongo.gridfile.writer class

Description

Objects of class "mongo.gridfile.writer" are used to buffer multiple writes to a single GridFS file.

Arguments

Details

Use mongo.gridfile.writer.create to create an object of this class, mongo.gridfile.writer.write to write data to it, and mongo.gridfile.writer.finish when done writing.

mongo.gridfile.writer objects have "mongo.gridfile.writer" as their class and contain an externally managed pointer to the actual data used to manage operations on the GridFS. This pointer is stored in the "mongo.gridfile" attribute of the object. The object also has a "mongo.gridfs" attribute holding a pointer to the mongo.gridfs object used in creation to prevent garbage collection on the mongo.gridfs object while the mongo.gridfile.writer is still active.

See Also

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

Examples

Run this code
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)
}

Run the code above in your browser using DataLab