This commit is contained in:
Alan K 2015-07-16 17:51:55 -04:00
parent 6549a98b6a
commit 047536c013
4 changed files with 66 additions and 65 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "filer", "name": "filer",
"version": "0.0.41", "version": "0.0.42",
"main": "dist/filer.js", "main": "dist/filer.js",
"ignore": [ "ignore": [
"build", "build",

121
dist/filer.js vendored
View File

@ -657,7 +657,6 @@ exports.SlowBuffer = SlowBuffer
exports.INSPECT_MAX_BYTES = 50 exports.INSPECT_MAX_BYTES = 50
Buffer.poolSize = 8192 // not used by this implementation Buffer.poolSize = 8192 // not used by this implementation
var kMaxLength = 0x3fffffff
var rootParent = {} var rootParent = {}
/** /**
@ -683,11 +682,14 @@ var rootParent = {}
* get the Object implementation, which is slower but will work correctly. * get the Object implementation, which is slower but will work correctly.
*/ */
Buffer.TYPED_ARRAY_SUPPORT = (function () { Buffer.TYPED_ARRAY_SUPPORT = (function () {
function Foo () {}
try { try {
var buf = new ArrayBuffer(0) var buf = new ArrayBuffer(0)
var arr = new Uint8Array(buf) var arr = new Uint8Array(buf)
arr.foo = function () { return 42 } arr.foo = function () { return 42 }
arr.constructor = Foo
return arr.foo() === 42 && // typed array instances can be augmented return arr.foo() === 42 && // typed array instances can be augmented
arr.constructor === Foo && // constructor can be set
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
} catch (e) { } catch (e) {
@ -695,6 +697,12 @@ Buffer.TYPED_ARRAY_SUPPORT = (function () {
} }
})() })()
function kMaxLength () {
return Buffer.TYPED_ARRAY_SUPPORT
? 0x7fffffff
: 0x3fffffff
}
/** /**
* Class: Buffer * Class: Buffer
* ============= * =============
@ -845,9 +853,9 @@ function allocate (that, length) {
function checked (length) { function checked (length) {
// Note: cannot use `length < kMaxLength` here because that fails when // Note: cannot use `length < kMaxLength` here because that fails when
// length is NaN (which is otherwise coerced to zero.) // length is NaN (which is otherwise coerced to zero.)
if (length >= kMaxLength) { if (length >= kMaxLength()) {
throw new RangeError('Attempt to allocate Buffer larger than maximum ' + throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
'size: 0x' + kMaxLength.toString(16) + ' bytes') 'size: 0x' + kMaxLength().toString(16) + ' bytes')
} }
return length | 0 return length | 0
} }
@ -939,29 +947,38 @@ Buffer.concat = function concat (list, length) {
} }
function byteLength (string, encoding) { function byteLength (string, encoding) {
if (typeof string !== 'string') string = String(string) if (typeof string !== 'string') string = '' + string
if (string.length === 0) return 0 var len = string.length
if (len === 0) return 0
switch (encoding || 'utf8') { // Use a for loop to avoid recursion
case 'ascii': var loweredCase = false
case 'binary': for (;;) {
case 'raw': switch (encoding) {
return string.length case 'ascii':
case 'ucs2': case 'binary':
case 'ucs-2': // Deprecated
case 'utf16le': case 'raw':
case 'utf-16le': case 'raws':
return string.length * 2 return len
case 'hex': case 'utf8':
return string.length >>> 1 case 'utf-8':
case 'utf8': return utf8ToBytes(string).length
case 'utf-8': case 'ucs2':
return utf8ToBytes(string).length case 'ucs-2':
case 'base64': case 'utf16le':
return base64ToBytes(string).length case 'utf-16le':
default: return len * 2
return string.length case 'hex':
return len >>> 1
case 'base64':
return base64ToBytes(string).length
default:
if (loweredCase) return utf8ToBytes(string).length // assume utf8
encoding = ('' + encoding).toLowerCase()
loweredCase = true
}
} }
} }
Buffer.byteLength = byteLength Buffer.byteLength = byteLength
@ -970,8 +987,7 @@ Buffer.byteLength = byteLength
Buffer.prototype.length = undefined Buffer.prototype.length = undefined
Buffer.prototype.parent = undefined Buffer.prototype.parent = undefined
// toString(encoding, start=0, end=buffer.length) function slowToString (encoding, start, end) {
Buffer.prototype.toString = function toString (encoding, start, end) {
var loweredCase = false var loweredCase = false
start = start | 0 start = start | 0
@ -1014,6 +1030,13 @@ Buffer.prototype.toString = function toString (encoding, start, end) {
} }
} }
Buffer.prototype.toString = function toString () {
var length = this.length | 0
if (length === 0) return ''
if (arguments.length === 0) return utf8Slice(this, 0, length)
return slowToString.apply(this, arguments)
}
Buffer.prototype.equals = function equals (b) { Buffer.prototype.equals = function equals (b) {
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
if (this === b) return true if (this === b) return true
@ -3693,13 +3716,11 @@ Object.defineProperty(LRUCache.prototype, "itemCount",
LRUCache.prototype.forEach = function (fn, thisp) { LRUCache.prototype.forEach = function (fn, thisp) {
thisp = thisp || this thisp = thisp || this
var i = 0 var i = 0;
var itemCount = this._itemCount for (var k = this._mru - 1; k >= 0 && i < this._itemCount; k--) if (this._lruList[k]) {
for (var k = this._mru - 1; k >= 0 && i < itemCount; k--) if (this._lruList[k]) {
i++ i++
var hit = this._lruList[k] var hit = this._lruList[k]
if (isStale(this, hit)) { if (this._maxAge && (Date.now() - hit.now > this._maxAge)) {
del(this, hit) del(this, hit)
if (!this._allowStale) hit = undefined if (!this._allowStale) hit = undefined
} }
@ -3754,24 +3775,19 @@ LRUCache.prototype.dumpLru = function () {
return this._lruList return this._lruList
} }
LRUCache.prototype.set = function (key, value, maxAge) { LRUCache.prototype.set = function (key, value) {
maxAge = maxAge || this._maxAge
var now = maxAge ? Date.now() : 0
if (hOP(this._cache, key)) { if (hOP(this._cache, key)) {
// dispose of the old one before overwriting // dispose of the old one before overwriting
if (this._dispose) if (this._dispose) this._dispose(key, this._cache[key].value)
this._dispose(key, this._cache[key].value) if (this._maxAge) this._cache[key].now = Date.now()
this._cache[key].now = now
this._cache[key].maxAge = maxAge
this._cache[key].value = value this._cache[key].value = value
this.get(key) this.get(key)
return true return true
} }
var len = this._lengthCalculator(value) var len = this._lengthCalculator(value)
var hit = new Entry(key, value, this._mru++, len, now, maxAge) var age = this._maxAge ? Date.now() : 0
var hit = new Entry(key, value, this._mru++, len, age)
// oversized objects fall out of cache automatically. // oversized objects fall out of cache automatically.
if (hit.length > this._max) { if (hit.length > this._max) {
@ -3783,16 +3799,14 @@ LRUCache.prototype.set = function (key, value, maxAge) {
this._lruList[hit.lu] = this._cache[key] = hit this._lruList[hit.lu] = this._cache[key] = hit
this._itemCount ++ this._itemCount ++
if (this._length > this._max) if (this._length > this._max) trim(this)
trim(this)
return true return true
} }
LRUCache.prototype.has = function (key) { LRUCache.prototype.has = function (key) {
if (!hOP(this._cache, key)) return false if (!hOP(this._cache, key)) return false
var hit = this._cache[key] var hit = this._cache[key]
if (isStale(this, hit)) { if (this._maxAge && (Date.now() - hit.now > this._maxAge)) {
return false return false
} }
return true return true
@ -3819,7 +3833,7 @@ LRUCache.prototype.del = function (key) {
function get (self, key, doUse) { function get (self, key, doUse) {
var hit = self._cache[key] var hit = self._cache[key]
if (hit) { if (hit) {
if (isStale(self, hit)) { if (self._maxAge && (Date.now() - hit.now > self._maxAge)) {
del(self, hit) del(self, hit)
if (!self._allowStale) hit = undefined if (!self._allowStale) hit = undefined
} else { } else {
@ -3830,18 +3844,6 @@ function get (self, key, doUse) {
return hit return hit
} }
function isStale(self, hit) {
if (!hit || (!hit.maxAge && !self._maxAge)) return false
var stale = false;
var diff = Date.now() - hit.now
if (hit.maxAge) {
stale = diff > hit.maxAge
} else {
stale = self._maxAge && (diff > self._maxAge)
}
return stale;
}
function use (self, hit) { function use (self, hit) {
shiftLU(self, hit) shiftLU(self, hit)
hit.lu = self._mru ++ hit.lu = self._mru ++
@ -3869,13 +3871,12 @@ function del (self, hit) {
} }
// classy, since V8 prefers predictable objects. // classy, since V8 prefers predictable objects.
function Entry (key, value, lu, length, now, maxAge) { function Entry (key, value, lu, length, now) {
this.key = key this.key = key
this.value = value this.value = value
this.lu = lu this.lu = lu
this.length = length this.length = length
this.now = now this.now = now
if (maxAge) this.maxAge = maxAge
} }
})() })()

6
dist/filer.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,7 @@
"idb", "idb",
"websql" "websql"
], ],
"version": "0.0.41", "version": "0.0.42",
"author": "Alan K <ack@modeswitch.org> (http://blog.modeswitch.org)", "author": "Alan K <ack@modeswitch.org> (http://blog.modeswitch.org)",
"homepage": "http://filerjs.github.io/filer", "homepage": "http://filerjs.github.io/filer",
"bugs": "https://github.com/filerjs/filer/issues", "bugs": "https://github.com/filerjs/filer/issues",