Last active
August 29, 2015 14:13
-
-
Save loveencounterflow/cb0b76c9d5d0b64137b0 to your computer and use it in GitHub Desktop.
Revisions
-
loveencounterflow revised this gist
Jan 12, 2015 . 1 changed file with 25 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ -------- listing keys up to LTE: 'a~' <Buffer 61 7e> 'a' 'abcdef' -------- listing keys up to LTE: 'aÿ' <Buffer 61 c3 bf> 'a' 'abcdef' 'aäöü' -------- listing keys up to LTE: 'a' <Buffer 61 ef bf bf> 'a' 'abcdef' 'aäöü' 'aΔ' 'a中' -------- listing keys up to LTE: <Buffer 61 ff> <Buffer 61 ff> 'a' 'abcdef' 'aäöü' 'aΔ' 'a中' 'a𠁩' -------- -
loveencounterflow revised this gist
Jan 12, 2015 . 2 changed files with 85 additions and 37 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,15 @@ // Generated by CoffeeScript 1.8.0 (function() { var $, D, db, db_route, feed, fs, gte, keys, log, new_db, read, rmrf, rpr, through2; fs = require('fs'); log = console.log; rpr = (require('util')).inspect; new_db = require('level'); through2 = require('through2'); rmrf = require('rimraf'); @@ -16,11 +18,8 @@ $ = D.remit.bind(D); feed = function(db, keys, handler) { var input, key, output, _i, _len; output = db.createWriteStream(); input = through2.obj(); input.pipe($(function(key, send) { @@ -29,7 +28,7 @@ value: 1 }); })).pipe(output).on('close', function() { return handler(); }); for (_i = 0, _len = keys.length; _i < _len; _i++) { key = keys[_i]; @@ -38,20 +37,50 @@ return input.end(); }; read = function(db, lte, gte, handler) { var input; log("listing keys up to LTE: " + (rpr(lte)) + " " + (rpr(new Buffer(lte)))); input = db.createKeyStream({ gte: gte, lte: lte }); return input.pipe($(function(key, send, end) { log(rpr(key)); if (end != null) { end(); return handler(); } })); }; if (module.parent == null) { keys = ['a', 'abcdef', 'aäöü', 'aΔ', 'a中', 'a𠁩', '~', 'äöü', 'ÿ', 'Δ', '中', '𠁩', '\uffff', '\xff']; db_route = '/tmp/level'; if (fs.existsSync(db_route)) { rmrf.sync(db_route); } db = new_db(db_route); gte = 'a'; feed(db, keys, function() { var lte; log('--------'); lte = 'a~'; return read(db, lte, gte, function() { log('--------'); lte = 'a\xff'; return read(db, lte, gte, function() { log('--------'); lte = 'a\uffff'; return read(db, lte, gte, function() { log('--------'); lte = new Buffer([0x61, 0xff]); return read(db, lte, gte, function() { return log('--------'); }); }); }); }); }); } }).call(this); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,54 +1,73 @@ ############################################################################################################ fs = require 'fs' log = console.log rpr = ( require 'util' ).inspect new_db = require 'level' through2 = require 'through2' rmrf = require 'rimraf' D = require 'pipedreams2' $ = D.remit.bind D #----------------------------------------------------------------------------------------------------------- feed = ( db, keys, handler ) -> output = db.createWriteStream() input = through2.obj() #......................................................................................................... input .pipe $ ( key, send ) -> send { key, value: 1, } .pipe output .on 'close', -> handler() #......................................................................................................... input.write key for key in keys input.end() #----------------------------------------------------------------------------------------------------------- read = ( db, lte, gte, handler ) -> log "listing keys up to LTE: #{rpr lte} #{rpr new Buffer lte}" input = db.createKeyStream { gte, lte, } input .pipe $ ( key, send, end ) -> log rpr key if end? end() handler() ############################################################################################################ unless module.parent? keys = [ 'a' 'abcdef' 'aäöü' 'aΔ' 'a中' 'a𠁩' '~' 'äöü' 'ÿ' 'Δ' '中' '𠁩' '\uffff' '\xff' ] #--------------------------------------------------------------------------------------------------------- db_route = '/tmp/level' rmrf.sync db_route if fs.existsSync db_route db = new_db db_route gte = 'a' #--------------------------------------------------------------------------------------------------------- feed db, keys, -> log '--------' lte = 'a~' read db, lte, gte, -> log '--------' lte = 'a\xff' read db, lte, gte, -> log '--------' lte = 'a\uffff' read db, lte, gte, -> log '--------' lte = new Buffer [ 0x61, 0xff, ] read db, lte, gte, -> log '--------' -
loveencounterflow revised this gist
Jan 12, 2015 . 1 changed file with 57 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ // Generated by CoffeeScript 1.8.0 (function() { var $, D, keys, log, new_db, read, rmrf, rpr, through2, write; new_db = require('level'); log = console.log; rpr = (require('util')).inspect; through2 = require('through2'); rmrf = require('rimraf'); D = require('pipedreams2'); $ = D.remit.bind(D); write = function(keys) { var db, db_route, input, key, output, _i, _len; db_route = '/tmp/level'; rmrf.sync(db_route); db = new_db(db_route); output = db.createWriteStream(); input = through2.obj(); input.pipe($(function(key, send) { return send({ key: key, value: 1 }); })).pipe(output).on('close', function() { return read(db); }); for (_i = 0, _len = keys.length; _i < _len; _i++) { key = keys[_i]; input.write(key); } return input.end(); }; read = function(db) { var input; input = db.createKeyStream({ gte: '', lte: 'xxx' }); return input.pipe($(function(key, send) { return log(rpr(key)); })); }; if (module.parent == null) { keys = ['abcdef', 'aäöü', 'a~', 'aΔ', 'äöü', '中中', '中', '𠁩', '中\xff', '𠁩\xff', '中\uffff', '中𠁩\uffff', '𠁩\uffff', 'a', 'a\xff', 'a\uffff']; write(keys); } }).call(this); -
loveencounterflow created this gist
Jan 12, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ ############################################################################################################ new_db = require 'level' log = console.log rpr = ( require 'util' ).inspect through2 = require 'through2' rmrf = require 'rimraf' D = require 'pipedreams2' $ = D.remit.bind D #----------------------------------------------------------------------------------------------------------- write = ( keys ) -> db_route = '/tmp/level' rmrf.sync db_route db = new_db db_route output = db.createWriteStream() input = through2.obj() #......................................................................................................... input .pipe $ ( key, send ) -> send { key, value: 1, } .pipe output .on 'close', -> read db #......................................................................................................... input.write key for key in keys input.end() #----------------------------------------------------------------------------------------------------------- read = ( db ) -> input = db.createKeyStream { gte: '', lte: 'xxx', } input.pipe $ ( key, send ) -> log rpr key ############################################################################################################ unless module.parent? keys = [ 'abcdef' 'aäöü' 'a~' 'aΔ' 'äöü' '中中' '中' '𠁩' '中\xff' '𠁩\xff' '中\uffff' '中𠁩\uffff' '𠁩\uffff' 'a' 'a\xff' 'a\uffff' ] write keys