File-like object used for reading from and writing to GridFS
Open a “file” in GridFS.
Application developers should generally not need to instantiate this class directly - instead see the gridfs.GridFS.open method.
Only a single opened GridFile instance may exist for a file in gridfs at any time. Care must be taken to close GridFile instances when done using them. GridFiles support the context manager protocol (the “with” statement).
Raises TypeError if file_spec is not an instance of dict, database is not an instance of pymongo.database.Database, or collection is not an instance of (str, unicode).
The file_spec argument must be a SON query specifier for the file to open. The first file matching the specifier will be opened. If no such files exist, a new file is created using the metadata in file_spec. The valid fields in a file_spec are as follows:
- “_id”: unique ID for this file * default: pymongo.objectid.ObjectId()
- “filename”: human name for the file
- “contentType”: valid mime-type for the file
- “length”: size of the file, in bytes * only used for querying, automatically set for inserts
- “chunkSize”: size of each of the chunks, in bytes * default: 256 kb
- “uploadDate”: date when the object was first stored * only used for querying, automatically set for inserts
- “aliases”: array of alias strings
- “metadata”: a SON document containing arbitrary data
Close the GridFile.
A closed GridFile cannot be read or written any more. Calling close() more than once is allowed.
Read at most size bytes from the file (less if there isn’t enough data).
The bytes are returned as a string object. If size is negative or omitted all data is read. Raises ValueError if this GridFile is already closed.
Rename this GridFile.
Due to buffering, the rename might not actually occur until flush() or close() is called.
Set the current position of the GridFile (read-mode files only).
Write a string to the GridFile. There is no return value.
Due to buffering, the string may not actually show up in the database until the flush() or close() method is called. Raises ValueError if this GridFile is already closed. Raises TypeErrer if str is not an instance of str.
Write a sequence of strings to the file.
Does not add seperators.