【问题标题】:GridFS: Cursor positioning works only one time after "seek"GridFS:光标定位在“寻找”后仅工作一次
【发布时间】:2013-03-01 18:24:58
【问题描述】:

我使用 GridStore.seek (GridStore.IO_SEEK_CUR) 将光标定位在一个文件中,但它只能工作一次。随着下一个read 和所有即将到来的读取和搜索,光标不再定位。如果我省略了 seek all read 的正确移动光标:

这是一个演示该行为的小示例:

var Db = require('mongodb').Db,
    Server = require('mongodb').Server,
    ObjectID = require('mongodb').ObjectID,
    GridStore = require('mongodb').GridStore;

var db = new Db('test', new Server("localhost", 27017, 
    {auto_reconnect: false, poolSize: 1}), {w:0, native_parser: false});

db.open(function(err, db) {
    var gridStore = new GridStore(db, "test_gs_seek_with_buffer", "w");
    gridStore.open(function(err, gridStore) {
        gridStore.write(new Buffer("012345678901234567890", "utf8"), function(err, gridStore) {
            gridStore.close(function(result) {
                var gridStore = new GridStore(db, "test_gs_seek_with_buffer", "r");
                gridStore.open(function(err, gridStore) {
                    gridStore.read( 5, function(err, data) {
                        console.log( data.toString() ); // "01234" --> CORRECT!
                        gridStore.seek(-2, GridStore.IO_SEEK_CUR, function(err, gridStore) {
                            gridStore.read( 5, function(err, data) {
                                console.log( data.toString() ); // "34567" --> CORRECT!
                                gridStore.seek(-2, GridStore.IO_SEEK_CUR, function(err, gridStore) {
                                    gridStore.read( 5, function(err, data) {
                                        console.log( data.toString() ); // "34567" --> FALSE! SHOULD BE "67890"!!!
                                        db.close();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
    });
});

错误、功能或开发人员?

感谢您的帮助!

【问题讨论】:

    标签: node.js mongodb gridfs


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      • 2021-05-25
      相关资源
      最近更新 更多