Learn R Programming

rmongodb (version 1.8.0)

mongo.gridfile.read: Read raw data from a mongo.gridfile

Description

Read raw data from a mongo.gridfile. The data read may span multiple chunks.

Usage

mongo.gridfile.read(gridfile, size)

Arguments

gridfile
A (mongo.gridfile) object.
size
(as.double) The number of bytes to read.

Value

(raw) The data read from emphgridfile. The length of this vector may be less than the requested size if there was not enough data remaining to be read. This length could also be 0 if an error occured during the operation. Check mongo.get.err() of the associated mongo connection object in this case.

Details

A mongo.gridfile file maintains a current read position which is advanced by the size of each read. This position is initially at offset 0.

Since this function returns raw data, you may want to use R's readBin() to unpack it.

See Also

mongo.gridfs, mongo.gridfs.find, mongo.gridfile, mongo.gridfile.get.descriptor, mongo.gridfile.get.filename, mongo.gridfile.get.length, mongo.gridfile.get.chunk.size, mongo.gridfile.get.chunk.count, mongo.gridfile.get.content.type, mongo.gridfile.get.upload.date, mongo.gridfile.get.md5, mongo.gridfile.get.metadata, mongo.gridfile.get.chunk, mongo.gridfile.get.chunks, mongo.gridfile.seek, mongo.gridfile.pipe.

Examples

Run this code
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    gridfs <- mongo.gridfs.create(mongo, "grid")
    mongo.gridfs.store.file(gridfs, "tests/test.R", "test.R")

    gf <- mongo.gridfs.find(gridfs, "test.R")
    if( !is.null(gf)){
      mongo.gridfile.seek(gf, 256*256*5)
      data <- mongo.gridfile.read(gf, 16384)

      mongo.gridfile.destroy(gf)
    }
    mongo.gridfs.destroy(gridfs)
}

Run the code above in your browser using DataLab