Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Class, Hash, and Queue got moved into their own repo.

  • Loading branch information...
commit 2a4c71ade4a71b40a09d49a50f88ebd1ea7e394b 1 parent 88f455c
@creationix authored
View
24 lib/class.js
@@ -1,24 +0,0 @@
-// This is my proto library but without changing Object.prototype
-// Then only sub-objects of Class have the special properties.
-var Class = module.exports = Object.create(Object.prototype, {
-
- // Implement extend for easy prototypal inheritance
- extend: {value: function extend(obj) {
- if (obj === undefined) return Object.create(this);
- obj.__proto__ = this;
- Object.freeze(obj); // Lock the prototype to enforce no changes
- return obj;
- }},
-
- // Implement new for easy self-initializing objects
- new: {value: function new_() {
- var obj = Object.create(this);
- if (typeof obj.initialize !== 'function') return obj;
-
- obj.initialize.apply(obj, arguments);
- Object.seal(obj); // Lock the object down so the fields are static
- return obj;
- }}
-
-});
-
View
2  lib/file.js
@@ -1,5 +1,5 @@
var fs = require('fs'),
- Queue = require('./queue');
+ Queue = require('queue');
// Reads from a given file descriptor at a specified position and length
// Handles all OS level chunking for you.
View
35 lib/hash.js
@@ -1,35 +0,0 @@
-
-// A Hash is an interable object
-var Hash = module.exports = Object.create(Object.prototype, {
- // Make for easy converting objects to hashes.
- new: {value: function (value) {
- if (value === undefined) return Object.create(Hash);
- value.__proto__ = Hash;
- return value;
- }},
- // Implements a forEach much like the one for Array.prototype.forEach.
- forEach: {value: function forEach(callback, thisObject) {
- var keys = Object.keys(this),
- length = keys.length;
- for (var i = 0; i < length; i++) {
- var key = keys[i];
- callback.call(thisObject, this[key], key, this);
- }
- }},
- // Implements a map much like the one for Array.prototype.map.
- // Returns a normal Array instance.
- map: {value: function map(callback, thisObject) {
- var keys = Object.keys(this),
- length = keys.length,
- accum = new Array(length);
- for (var i = 0; i < length; i++) {
- var key = keys[i];
- accum[i] = callback.call(thisObject, this[key], key, this);
- }
- return accum;
- }},
- length: {get: function length() {
- return Object.keys(this).length;
- }}
-});
-Object.freeze(Hash);
View
6 lib/nstore.js
@@ -1,9 +1,9 @@
var Path = require('path'),
fs = require('fs'),
Step = require('step'),
- Class = require('./class'),
- Hash = require('./hash'),
- Queue = require('./queue'),
+ Class = require('class'),
+ Hash = require('hash'),
+ Queue = require('queue'),
File = require('./file');
const CHUNK_LENGTH = 40 * 1024,
View
29 lib/queue.js
@@ -1,29 +0,0 @@
-var Class = require('./class');
-
-// If a large number of writes gets queued up, the shift call normally
-// eats all the CPU. This implementes a faster queue.
-var Queue = module.exports = Class.extend({
- initialize: function initialize() {
- if (this === Queue) throw new Error("Cann't use Queue directly");
- this.tail = [];
- this.head = Array.prototype.slice.call(arguments);
- this.offset = 0;
- },
- shift: function shift() {
- if (this.offset === this.head.length) {
- var tmp = this.head;
- tmp.length = 0;
- this.head = this.tail;
- this.tail = tmp;
- this.offset = 0;
- if (this.head.length === 0) return;
- }
- return this.head[this.offset++];
- },
- push: function push(item) {
- return this.tail.push(item);
- },
- get length() {
- return this.head.length - this.offset + this.tail.length;
- }
-});
Please sign in to comment.
Something went wrong with that request. Please try again.