Godeps/_workspace/src/gopkg.in/mgo.v2/gridfs.go
func (gfs *GridFS) OpenId(id interface{}) (file *GridFile, err error) {
	var doc gfsFile
	err = gfs.Files.Find(bson.M{"_id": id}).One(&doc)
	if err != nil {
		return
	}
	file = gfs.newFile()
	file.mode = gfsReading
	file.doc = doc
	return
}
func (gfs *GridFS) OpenId(id interface{}) (file *GridFile, err error) {
	var doc gfsFile
	err = gfs.Files.Find(bson.M{"_id": id}).One(&doc)
	if err != nil {
		return
	}
	file = gfs.newFile()
	file.mode = gfsReading
	file.doc = doc
	return
}
func ( gfs * GridFS ) OpenId ( id interface { } ) ( file * GridFile , err error ) { var doc gfsFile err = gfs . Files . Find ( bson . M { " " : id } ) . One ( & doc ) if err != nil { return } file = gfs . newFile ( ) file . mode = gfsReading file . doc = doc return }
// OpenId returns the file with the provided id, for reading.
// If the file isn't found, err will be set to mgo.ErrNotFound.
//
// It's important to Close files whether they are being written to
// or read from, and to check the err result to ensure the operation
// completed successfully.
//
// The following example will print the first 8192 bytes from the file:
//
//     func check(err error) {
//         if err != nil {
//             panic(err.String())
//         }
//     }
//     file, err := db.GridFS("fs").OpenId(objid)
//     check(err)
//     b := make([]byte, 8192)
//     n, err := file.Read(b)
//     check(err)
//     fmt.Println(string(b))
//     check(err)
//     err = file.Close()
//     check(err)
//     fmt.Printf("%d bytes read\n", n)
//
// The io.Reader interface is implemented by *GridFile and may be used to
// deal with it.  As an example, the following snippet will dump the whole
// file into the standard output:
//
//     file, err := db.GridFS("fs").OpenId(objid)
//     check(err)
//     err = io.Copy(os.Stdout, file)
//     check(err)
//     err = file.Close()
//     check(err)
//
OpenId returns the file with the provided id for reading . If the file isn t found err will be set to mgo . ErrNotFound . It s important to Close files whether they are being written to or read from and to check the err result to ensure the operation completed successfully . The following example will print the first 8192 bytes from the file : func check ( err error ) { if err ! = nil { panic ( err . String () ) } } file err : = db . GridFS ( fs ) . OpenId ( objid ) check ( err ) b : = make ( [] byte 8192 ) n err : = file . Read ( b ) check ( err ) fmt . Println ( string ( b )) check ( err ) err = file . Close () check ( err ) fmt . Printf ( %d bytes read \ n n ) The io . Reader interface is implemented by * GridFile and may be used to deal with it . As an example the following snippet will dump the whole file into the standard output : file err : = db . GridFS ( fs ) . OpenId ( objid ) check ( err ) err = io . Copy ( os . Stdout file ) check ( err ) err = file . Close () check ( err )