0

我正在使用这个函数来检索文件。在从请求中提取 md5sum 之前还有其他一些函数调用,确保文件存在,然后调用 buildFile()。

 FileChunker.prototype.buildFile = function(file, callback) {
         self = this;
         console.log(file);

         this.gridfs.get(file._id, function(error, data) {
                 if (error) {
                         console.log(error);
                         callback(error);
                 }
                 else {
                         callback(null, data);
                 }       
         });     
    }; 

这是生成的十六进制转储。

磁盘上的原始文件(通过 mongofiles 导入,可以通过 mongofiles 正确检索)

~/_nodejs% hexdump -C test.txt
00000000  41 42 43 44 45 46 47 48  49 4a 4b 4c 4d 4e 4f 50  |ABCDEFGHIJKLMNOP|
00000010  0a                                                |.|
00000011

nodejs的输出

~/_nodejs% hexdump -C OUTPUT
00000000  11 00 00 00 41 42 43 44  45 46 47 48 49 4a 4b 4c  |....ABCDEFGHIJKL|
00000010  4d                                                |M|
00000011

如果我们console.log是 Buffer 对象,我们也会看到额外的数据:

 <Buffer 11 00 00 00 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d>

一段时间以来,我一直在为此苦苦挣扎,不知道下一步该做什么。这就像gridfs.get()只是返回错误的数据。

4

1 回答 1

0

您可以在 git repo 上发布问题,请提供节点版本、mongodb 版本、驱动程序版本和重现它的步骤(最好是代码)。否则我在这里有点盲目。

于 2012-06-01T06:57:23.360 回答