forked from LeisureLink/block-file
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Phillip Clark
committed
May 16, 2016
0 parents
commit c128e4f
Showing
22 changed files
with
1,041 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
coverage | ||
.idea/ | ||
.settings/ | ||
build |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
|
||
extends: eslint:recommended | ||
|
||
env: | ||
node: true | ||
es6: true | ||
|
||
parser: babel-eslint | ||
|
||
rules: | ||
block-scoped-var: 2 | ||
camelcase: 2 | ||
complexity: | ||
- 2 | ||
- 7 | ||
consistent-return: 2 | ||
dot-location: | ||
- 2 | ||
- property | ||
eol-last: 2 | ||
eqeqeq: | ||
- 2 | ||
- smart | ||
indent: | ||
- 2 | ||
- 2 | ||
linebreak-style: | ||
- 2 | ||
- unix | ||
no-case-declarations: 2 | ||
no-cond-assign: 2 | ||
no-constant-condition: 2 | ||
no-debugger: 2 | ||
no-div-regex: 2 | ||
no-dupe-args: 2 | ||
no-dupe-keys: 2 | ||
no-else-return: 2 | ||
no-eval: 2 | ||
no-extend-native: 2 | ||
no-extra-bind: 2 | ||
no-invalid-this: 2 | ||
no-loop-func: 2 | ||
no-mixed-spaces-and-tabs: 2 | ||
no-multi-spaces: 2 | ||
no-nested-ternary: 2 | ||
no-new-func: 2 | ||
no-new-require: 2 | ||
no-new-wrappers: 2 | ||
no-proto: 2 | ||
no-redeclare: | ||
- 2 | ||
- { "builtinGlobals": true } | ||
no-self-compare: 2 | ||
no-trailing-spaces: 2 | ||
no-undef: 2 | ||
no-underscore-dangle: 2 | ||
no-unused-vars: 2 | ||
no-use-before-define: 2 | ||
no-void: 2 | ||
no-with: 2 | ||
object-curly-spacing: | ||
- 2 | ||
- always | ||
quotes: | ||
- 2 | ||
- single | ||
- avoid-escape | ||
radix: | ||
- 2 | ||
- always | ||
semi: | ||
- 2 | ||
- always | ||
space-in-parens: | ||
- 2 | ||
- never | ||
vars-on-top: 2 |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
docs | ||
build | ||
coverage | ||
.coverag* |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"js": { | ||
"indent_char": " ", | ||
"indent_size": 2 | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
doc/ | ||
src/ | ||
test/ | ||
.babel* | ||
.eslint* | ||
.jsbeaut* | ||
.git* | ||
esdoc* | ||
circle.yml |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 LeisureLink, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# block-file [](https://circleci.com/gh/LeisureLink/block-file) | ||
|
||
A block-read, buffered, random-access file implementation for nodejs. | ||
|
||
## Why | ||
|
||
When working with random-access files, access is often less than truly random. More often, reads occur around hot-spots in the file and writes tend to occur near recent reads. Think about database-style binary files; often a record is read, modified, and written back to the file. In such a case, block reads and a little bit of buffering can dramatically improve performance. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install block-file | ||
``` | ||
|
||
## Use | ||
|
||
**es5** | ||
```javascript | ||
var BlockFile = require('block-file').BlockFile; | ||
``` | ||
|
||
**es6** | ||
```javascript | ||
import { BlockFile } from 'block-file'; | ||
``` | ||
|
||
## License | ||
|
||
[MIT](https://github.com/LeisureLink/block-file/blob/master/LICENSE) |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
machine: | ||
timezone: | ||
America/Denver | ||
node: | ||
version: 4.2.4 | ||
deployment: | ||
production: | ||
tag: /v.*/ | ||
commands: | ||
- npm publish |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"source": "./src", | ||
"destination": "./docs", | ||
"coverage": true | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.wal | ||
*.wal.lix |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const WriteAheadLog = require('../').WriteAheadLog; | ||
|
||
const stdout = console.log.bind(console); // eslint-disable-line no-console | ||
const stderr = console.error.bind(console); // eslint-disable-line no-console | ||
|
||
function job(jobId) { | ||
// this is a simulation, you would probably do something more interesting. | ||
return new Promise((resolve) => { | ||
stdout(`performing job: ${jobId}`); | ||
setTimeout(() => { | ||
stdout(`done with job: ${jobId}`); | ||
resolve(); | ||
}, 1000); | ||
}); | ||
} | ||
|
||
const path = __filename + '.wal'; | ||
const writable = true; | ||
|
||
WriteAheadLog.openOrCreate({ path, writable }) | ||
// usually when you open a log you'll want to run recovery in case of prior failure. | ||
// here we're telling wal to truncate all uncommitted entries. | ||
.then(wal => wal.recover(false)) | ||
.then(wal => { | ||
let committed = wal.commitHead; | ||
|
||
// We'll just use the LSN as our job number... | ||
let jobId = committed + 1; | ||
let data = new Buffer(`job #${jobId}\r\n`); | ||
|
||
// 1. Log some data; this data is opaque to the log... | ||
return wal.write(data) | ||
.then(lsn => { | ||
|
||
// 2. Do the actual work... | ||
return job(jobId).then(() => { | ||
|
||
// 3. Commit the log up to the LSN. | ||
return wal.commit(lsn) | ||
.then(() => { | ||
stdout(`committed job: ${jobId}`); | ||
}); | ||
}); | ||
}) | ||
// perform a normal close. | ||
.then(() => wal.close()); | ||
}) | ||
.catch(err => stderr('' + err)); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('./build/'); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "block-file", | ||
"version": "0.1.0", | ||
"description": "A block-read, buffered, random-access file implementation for nodejs.", | ||
"keywords": [], | ||
"main": "index.js", | ||
"scripts": { | ||
"docs": "esdoc -c ./esdoc.json", | ||
"docs:watch": "chokidar -i doc -c 'npm run doc' .", | ||
"lint": "eslint .", | ||
"pretest": "npm run build", | ||
"test": "tape -r babel-register test/**/*.test.js | tap-spec", | ||
"test:watch": "chokidar -i build . -c 'npm test'", | ||
"cover": "istanbul cover test", | ||
"ci": "npm run lint && npm test", | ||
"clean": "rm -rf ./build ./coverage .coverag*", | ||
"rebuild": "npm run clean && babel src/ -s inline -d build/", | ||
"build": "babel src/ -s inline -d build/", | ||
"prepublish": "npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/LeisureLink/block-read" | ||
}, | ||
"author": "[email protected]", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/LeisureLink/block-read/issues" | ||
}, | ||
"homepage": "https://github.com/LeisureLink/block-read", | ||
"dependencies": { | ||
"assert-plus": "^1.0.0", | ||
"btreejs": "^0.3.0", | ||
"es6-promisify": "^4.0.0", | ||
"ranfile": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.8.0", | ||
"babel-core": "^6.8.0", | ||
"babel-eslint": "^6.0.4", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-register": "^6.8.0", | ||
"chokidar-cli": "^1.2.0", | ||
"deep-equal": "^1.0.1", | ||
"esdoc": "^0.4.7", | ||
"istanbul": "^0.4.3", | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.5.1", | ||
"tmp": "0.0.28" | ||
} | ||
} |
Oops, something went wrong.