my8bird/node-leveldb — pull request #10 by mikepb (2012-02-12 04:53:43+00:00)
Title: More JavaScript-like API

I'm satisfied with the stability of the new API:

- CoffeeScript is commented, but if you prefer JS, do `cake build:coffee` to compile to JS. It more or less reads just as well.
- I worked hard to not have memory leaks, but I don't know if this is completely true.
- Tests don't test options, but do test everything else, for now.
- Not production tested!

There are also some caveats from the requirements of the underlying leveldb library:

- Batch objects are read-locked when committing, meaning that `batch.write()` (async) with concurrent `batch.put()` or `batch.del()` will throw an error.
- Iterator objects support only one operation at a time, meaning that running two methods concurrently (async) will throw an error.
- There is an advanced option on the native iterator object `iterator.self.refSlice = true` to return buffers which ref the returned leveldb Slice instances instead of copying the data into a new buffer. Doesn't work without the `as_buffer` option for iterator read operations. The caveat is that the buffer is only valid until the next seek and may crash the program if used after seek. Use with care.

Cheers.