Skip to content

Commit cc449c9

Browse files
author
Divjot Arora
committed
Parse file length as int64 in gridfs and update tests to use DownloadToStream.
GODRIVER-654 Change-Id: Id79b0074ada75183f99917385552bf24243116c3
1 parent ec0aedd commit cc449c9

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

mongo/gridfs/bucket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func (b *Bucket) openDownloadStream(filter interface{}, opts ...*options.FindOpt
336336
return nil, err
337337
}
338338

339-
fileLen := fileLenElem.Int32()
339+
fileLen := fileLenElem.Int64()
340340
if fileLen == 0 {
341341
return newDownloadStream(nil, b.chunkSize, 0), nil
342342
}

mongo/gridfs/gridfs_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ func loadInitialFiles(t *testing.T, data dataSection) int32 {
9292
testhelpers.RequireNil(t, err, "error converting raw message to bytes: %s", err)
9393
doc := bsonx.Doc{}
9494
err = bson.UnmarshalExtJSON(docBytes, false, &doc)
95-
//fmt.Println(doc.LookupElement("_id"))
9695
testhelpers.RequireNil(t, err, "error creating file document: %s", err)
9796

98-
// convert n from int64 to int32
97+
// convert length from int32 to int64
98+
if length, err := doc.LookupErr("length"); err == nil {
99+
doc = doc.Delete("length")
100+
doc = doc.Append("length", bsonx.Int64(int64(length.Int32())))
101+
}
99102
if cs, err := doc.LookupErr("chunkSize"); err == nil {
100-
doc = doc.Delete("chunkSize")
101103
chunkSize = cs.Int32()
102-
doc = append(doc, bsonx.Elem{"chunkSize", bsonx.Int32(chunkSize)})
103104
}
104105

105106
filesDocs = append(filesDocs, doc)
@@ -129,7 +130,6 @@ func loadInitialFiles(t *testing.T, data dataSection) int32 {
129130
}
130131

131132
if len(filesDocs) > 0 {
132-
//fmt.Println(filesDocs)
133133
_, err := files.InsertMany(ctx, filesDocs)
134134
testhelpers.RequireNil(t, err, "error inserting into files: %s", err)
135135
_, err = expectedFiles.InsertMany(ctx, filesDocs)
@@ -208,7 +208,7 @@ func runGridFSTestFile(t *testing.T, filepath string, db *mongo.Database) {
208208
runUploadFromStreamTest(t, test, bucket)
209209
case "download":
210210
runDownloadTest(t, test, bucket)
211-
//runDownloadToStreamTest(t, test, bucket)
211+
runDownloadToStreamTest(t, test, bucket)
212212
case "download_by_name":
213213
runDownloadByNameTest(t, test, bucket)
214214
runDownloadByNameToStreamTest(t, test, bucket)

0 commit comments

Comments
 (0)