Giter Site home page Giter Site logo

node-cdb's People

Contributors

adminxvii avatar ericnorris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-cdb's Issues

writing characters beyond ASCII

First, thank you for making available what appears to be the only node module for writing cdb files!

I'm having some trouble with writing/reading characters beyond ASCII.

Here's my code for writing two values to the same key, the first being in Chinese:

var cdb = require('constant-db');
var writer = new cdb.writable('./test.cdb');
writer.open(function (err) {
    if (err) {
        throw err;
    }
    writer.put('myKey', '你好');
    writer.put('myKey', 'test value!');
    writer.close(function (err) {
        if (err) {
            throw err;
        }
    });
});

And here's my code for reading the values:

var cdb = require('constant-db');
var reader = new cdb.readable('./test.cdb');
reader.open(function (err) {
    if (err) {
        throw err;
    }
    reader.get('myKey', function (err, data) {
        if (err) {
            throw err;
        }
        console.log(data);
        var buf = new Buffer(data);
        console.log(buf.toString('utf8'));

        reader.getNext(function (err, data) {
            if (err) {
                throw err;
            }
            console.log(data);
            var buf = new Buffer(data);
            console.log(buf.toString('utf8'));

            reader.close(function (err) {
                if (err) {
                    throw err;
                }
            });
        });
    });
});

And here's the output:

<Buffer 00 00>

<Buffer 74 65 73 74 21>
test value!

Notice that the buffer for the first value is all zeroes. Am I doing something wrong, or is this a bug?

Feature request

This is probably a bit misplaced and you are not a newbee JS tutor. So sorry.
But:
Is it troublesome to extend your excellent examples to the typical user case where you call it from inside a function and the data part is not simply printed to the console.log, but passed back through the callback chain to the calling function? I guess it is easy if you know how to do it, but I am pulling my hairs on these freaky callback chains 📦
var readable = require('constant-db').readable;

var getTheRecord = function(key){

    var reader = new readable('./cdbfile');

    reader.open(function cdbOpened(err) {

        reader.get( key , function gotRecord(err, data) {

            return data;  // instead of console.log(data); 

            reader.close(function cdbClosed(err) {
                console.log('awesome!');
            });
        });
    });
});

Which gives you "hello world!" when calling
console.log( getTheRecord('meow'));

I am banging my head against the wall :) This exercise is very informative about the intention of nonblocking code - that it does not block and not wait... whatever I do I get returned "undefined" since the engine simply does not wait for the variable to return.... I looked at promises, but I think one would rather use callbacks.

Sorry for bugging you, but I suspect it is an easy issue for a node pro?

Thanks anyway for your brilliant tool and I will figure it out anyway anyway :)

R

The example of get() in "Readable cdb" is not working

Hi,
I am new to js, node and cdb. I started writing my first small scripts and want to read from a cdb.

When pasting your small examples for writable and readable into say "WritableCDB.js" and "ReadableCDB.js" and executing them in the shell with "node Writable.js" and "node Readable.js" the former is working correctly and the cdbfile is correctly created - I validated the file with freecdb.

But:

node ReadableCDB.js

returns "undefined" and not "hello world".

I changed "console.log(data)" to "console.log(err,data)" and the error code is

[Error: EBADF, read] errno: 9, code: 'EBADF'

I did some search on this one and it seems that close() is called before the data is read. I have not understood the callback structure good enough to know how to correct it, but commenting out the close() line returns the data.

But: in hex encoding :)

So:

reader.open(function cdbOpened(err) {
    reader.get('meow', function gotRecord(err, data) {
        console.log( data.toString() );
    });
});

Produces "hello world", but then the connection is not closed.
Would be curious how to get the callback right.

Thanks,
Reinhard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.