mongo.gridfile.writer.write: Write raw data to a buffered GridFS file

Description Usage Arguments Details See Also Examples

View source: R/gridfs.R

Description

Write raw data to a buffered GridFS file. The data is buffered and sent to the server in 256k chunks as it accumulates.

Usage

1

Arguments

gfw

A (mongo.gridfile.writer) object.

raw

(raw) The data to write to the GridFS file.

Details

This function only handles the RAW type. Use writeBin() as necessary to pack your data appropriately for storage. See the examples and R's documentation on writeBin().

Use mongo.gridfs.store() when you only need to write one data packet as a complete GridFS file.

See Also

mongo.gridfs,
mongo.gridfile.writer.create,
mongo.gridfile.writer,
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
21
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.