0

I am positioning the cursor within a file with GridStore.seek (GridStore.IO_SEEK_CUR) but it works only one time. With the next read and all forthcoming read's and seek's the cursor is not positioned any more. If I omit the seek all read's move the cursor foward correctly:

Here is a small example that demonstrates the behavior:

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();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
    });
});

Bug, feature or developer?

Thanks for your help!

heinob
  • 19,127
  • 5
  • 41
  • 61

1 Answers1

0

The issue has been fixed in the meantime. See here: https://github.com/mongodb/node-mongodb-native/commit/85d0f7da21c3bcc1dfc2d4a3f91a8df8102daacc

heinob
  • 19,127
  • 5
  • 41
  • 61