[Pkg-javascript-commits] [node-leveldown] 193/492: move encodingOpts levelup.js -> util.js
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:58 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.
commit fd96244c83c39ae5e5c0e01c807921d7ed697392
Author: Lars-Magnus Skog <lars.magnus.skog at gmail.com>
Date: Wed Jan 30 01:54:18 2013 +0100
move encodingOpts levelup.js -> util.js
---
lib/levelup.js | 10 ++--------
lib/util.js | 35 ++++++++++++++++++++++++++++-------
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/lib/levelup.js b/lib/levelup.js
index 8075bdd..c064b18 100644
--- a/lib/levelup.js
+++ b/lib/levelup.js
@@ -14,7 +14,7 @@ var bridge = require('bindings')('levelup.node')
, extend = require('util')._extend
, toEncoding = require('./util').toEncoding
, toSlice = require('./util').toSlice
- , encodings = require('./util').encodings
+ , encodingOpts = require('./util').encodingOpts
, defaultOptions = {
createIfMissing : true
@@ -25,12 +25,6 @@ var bridge = require('bindings')('levelup.node')
, compression : true
}
- , encodingOpts = (function () {
- var eo = {}
- encodings.forEach(function (e) { eo[e] = { encoding: e } })
- return eo
- }())
-
, getOptions = function (options, globalOptions) {
return typeof options == 'string' // just an encoding
? options = extend(
@@ -61,7 +55,7 @@ var bridge = require('bindings')('levelup.node')
, isOpen = function () { return status == 'open' }
, isClosed = function () { return (/^clos/).test(status) }
, inLimbo = function () { return !isOpen() && !isClosed() }
-
+
if (typeof options == 'function') {
callback = options
options = {}
diff --git a/lib/util.js b/lib/util.js
index d5aa854..77e971e 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -1,20 +1,35 @@
/* Copyright (c) 2012-2013 LevelUP contributors
* See list at <https://github.com/rvagg/node-levelup#contributing>
- * MIT +no-false-attribs License <https://github.com/rvagg/node-levelup/blob/master/LICENSE>
+ * MIT +no-false-attribs License
+ * <https://github.com/rvagg/node-levelup/blob/master/LICENSE>
*/
-var encodings = 'hex utf8 utf-8 ascii binary base64 ucs2 ucs-2 utf16le utf-16le'.split(' ')
+var encodings = [
+ 'hex'
+ , 'utf8'
+ , 'utf-8'
+ , 'ascii'
+ , 'binary'
+ , 'base64'
+ , 'ucs2'
+ , 'ucs-2'
+ , 'utf16le'
+ , 'utf-16le'
+ ]
, toSlice = (function () {
var slicers = {}
+ , isBuffer = function (data) {
+ return data === undefined || data === null || Buffer.isBuffer(data)
+ }
slicers.json = JSON.stringify.bind(JSON)
slicers.utf8 = function (data) {
- return data === undefined || data === null || Buffer.isBuffer(data) ? data : String(data)
+ return isBuffer(data) ? data : String(data)
}
encodings.forEach(function (enc) {
if (slicers[enc]) return
slicers[enc] = function (data) {
- return data === undefined || data === null || Buffer.isBuffer(data) ? data : new Buffer(data, enc)
+ return isBuffer(data) ? data : new Buffer(data, enc)
}
})
return slicers
@@ -34,17 +49,23 @@ var encodings = 'hex utf8 utf-8 ascii binary base64 ucs2 ucs-2 utf16le utf-16le'
, copy = function (srcdb, dstdb, callback) {
srcdb.readStream()
- .pipe(dstdb.writeStream({useBatch:false}))
+ .pipe(dstdb.writeStream({ useBatch: false }))
.on('close', callback ? callback : function () {})
.on('error', callback ? callback : function (err) { throw err })
}
, setImmediate = global.setImmediate || process.nextTick
+ , encodingOpts = (function () {
+ var eo = {}
+ encodings.forEach(function (e) { eo[e] = { encoding: e } })
+ return eo
+ }())
+
module.exports = {
- encodings : encodings
- , toSlice : toSlice
+ toSlice : toSlice
, toEncoding : toEncoding
, copy : copy
, setImmediate : setImmediate
+ , encodingOpts : encodingOpts
}
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git
More information about the Pkg-javascript-commits
mailing list