Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
2.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
shaungrady committed Aug 24, 2016
1 parent c5d8d05 commit 55cfced
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 63 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-http-etag",
"version": "2.0.8",
"version": "2.0.9",
"description": "Angular module for easy ETag-based caching of $http responses",
"homepage": "https://github.com/shaungrady/angular-http-etag",
"author": "Shaun Grady (http://shaungrady.com)",
Expand Down
198 changes: 140 additions & 58 deletions release/angular-http-etag.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* angular-http-etag v2.0.8
* angular-http-etag v2.0.9
* Shaun Grady (http://shaungrady.com), 2016
* https://github.com/shaungrady/angular-http-etag
* Module: Universal Module Definition
Expand Down Expand Up @@ -299,6 +299,8 @@ if (Buffer.TYPED_ARRAY_SUPPORT) {
function assertSize (size) {
if (typeof size !== 'number') {
throw new TypeError('"size" argument must be a number')
} else if (size < 0) {
throw new RangeError('"size" argument must not be negative')
}
}

Expand Down Expand Up @@ -362,12 +364,20 @@ function fromString (that, string, encoding) {
var length = byteLength(string, encoding) | 0
that = createBuffer(that, length)

that.write(string, encoding)
var actual = that.write(string, encoding)

if (actual !== length) {
// Writing a hex string, for example, that contains invalid characters will
// cause everything after the first invalid character to be ignored. (e.g.
// 'abxxcd' will be treated as 'ab')
that = that.slice(0, actual)
}

return that
}

function fromArrayLike (that, array) {
var length = checked(array.length) | 0
var length = array.length < 0 ? 0 : checked(array.length) | 0
that = createBuffer(that, length)
for (var i = 0; i < length; i += 1) {
that[i] = array[i] & 255
Expand Down Expand Up @@ -436,7 +446,7 @@ function fromObject (that, obj) {
}

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.)
if (length >= kMaxLength()) {
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
Expand Down Expand Up @@ -485,9 +495,9 @@ Buffer.isEncoding = function isEncoding (encoding) {
case 'utf8':
case 'utf-8':
case 'ascii':
case 'latin1':
case 'binary':
case 'base64':
case 'raw':
case 'ucs2':
case 'ucs-2':
case 'utf16le':
Expand Down Expand Up @@ -548,9 +558,8 @@ function byteLength (string, encoding) {
for (;;) {
switch (encoding) {
case 'ascii':
case 'latin1':
case 'binary':
case 'raw':
case 'raws':
return len
case 'utf8':
case 'utf-8':
Expand Down Expand Up @@ -623,8 +632,9 @@ function slowToString (encoding, start, end) {
case 'ascii':
return asciiSlice(this, start, end)

case 'latin1':
case 'binary':
return binarySlice(this, start, end)
return latin1Slice(this, start, end)

case 'base64':
return base64Slice(this, start, end)
Expand Down Expand Up @@ -676,6 +686,20 @@ Buffer.prototype.swap32 = function swap32 () {
return this
}

Buffer.prototype.swap64 = function swap64 () {
var len = this.length
if (len % 8 !== 0) {
throw new RangeError('Buffer size must be a multiple of 64-bits')
}
for (var i = 0; i < len; i += 8) {
swap(this, i, i + 7)
swap(this, i + 1, i + 6)
swap(this, i + 2, i + 5)
swap(this, i + 3, i + 4)
}
return this
}

Buffer.prototype.toString = function toString () {
var length = this.length | 0
if (length === 0) return ''
Expand Down Expand Up @@ -758,7 +782,73 @@ Buffer.prototype.compare = function compare (target, start, end, thisStart, this
return 0
}

function arrayIndexOf (arr, val, byteOffset, encoding) {
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
//
// Arguments:
// - buffer - a Buffer to search
// - val - a string, Buffer, or number
// - byteOffset - an index into `buffer`; will be clamped to an int32
// - encoding - an optional encoding, relevant is val is a string
// - dir - true for indexOf, false for lastIndexOf
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
// Empty buffer means no match
if (buffer.length === 0) return -1

// Normalize byteOffset
if (typeof byteOffset === 'string') {
encoding = byteOffset
byteOffset = 0
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff
} else if (byteOffset < -0x80000000) {
byteOffset = -0x80000000
}
byteOffset = +byteOffset // Coerce to Number.
if (isNaN(byteOffset)) {
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
byteOffset = dir ? 0 : (buffer.length - 1)
}

// Normalize byteOffset: negative offsets start from the end of the buffer
if (byteOffset < 0) byteOffset = buffer.length + byteOffset
if (byteOffset >= buffer.length) {
if (dir) return -1
else byteOffset = buffer.length - 1
} else if (byteOffset < 0) {
if (dir) byteOffset = 0
else return -1
}

// Normalize val
if (typeof val === 'string') {
val = Buffer.from(val, encoding)
}

// Finally, search either indexOf (if dir is true) or lastIndexOf
if (Buffer.isBuffer(val)) {
// Special case: looking for empty string/buffer always fails
if (val.length === 0) {
return -1
}
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
} else if (typeof val === 'number') {
val = val & 0xFF // Search for a byte value [0-255]
if (Buffer.TYPED_ARRAY_SUPPORT &&
typeof Uint8Array.prototype.indexOf === 'function') {
if (dir) {
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
} else {
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
}
}
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
}

throw new TypeError('val must be string, number or Buffer')
}

function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
var indexSize = 1
var arrLength = arr.length
var valLength = val.length
Expand All @@ -785,60 +875,45 @@ function arrayIndexOf (arr, val, byteOffset, encoding) {
}
}

var foundIndex = -1
for (var i = byteOffset; i < arrLength; ++i) {
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
if (foundIndex === -1) foundIndex = i
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
} else {
if (foundIndex !== -1) i -= i - foundIndex
foundIndex = -1
var i
if (dir) {
var foundIndex = -1
for (i = byteOffset; i < arrLength; i++) {
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
if (foundIndex === -1) foundIndex = i
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
} else {
if (foundIndex !== -1) i -= i - foundIndex
foundIndex = -1
}
}
} else {
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
for (i = byteOffset; i >= 0; i--) {
var found = true
for (var j = 0; j < valLength; j++) {
if (read(arr, i + j) !== read(val, j)) {
found = false
break
}
}
if (found) return i
}
}

return -1
}

Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
if (typeof byteOffset === 'string') {
encoding = byteOffset
byteOffset = 0
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff
} else if (byteOffset < -0x80000000) {
byteOffset = -0x80000000
}
byteOffset >>= 0

if (this.length === 0) return -1
if (byteOffset >= this.length) return -1

// Negative offsets start from the end of the buffer
if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)

if (typeof val === 'string') {
val = Buffer.from(val, encoding)
}

if (Buffer.isBuffer(val)) {
// special case: looking for empty string/buffer always fails
if (val.length === 0) {
return -1
}
return arrayIndexOf(this, val, byteOffset, encoding)
}
if (typeof val === 'number') {
if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
}
return arrayIndexOf(this, [ val ], byteOffset, encoding)
}
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
return this.indexOf(val, byteOffset, encoding) !== -1
}

throw new TypeError('val must be string, number or Buffer')
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
}

Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
return this.indexOf(val, byteOffset, encoding) !== -1
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
}

function hexWrite (buf, string, offset, length) {
Expand All @@ -855,7 +930,7 @@ function hexWrite (buf, string, offset, length) {

// must be an even number of digits
var strLen = string.length
if (strLen % 2 !== 0) throw new Error('Invalid hex string')
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')

if (length > strLen / 2) {
length = strLen / 2
Expand All @@ -876,7 +951,7 @@ function asciiWrite (buf, string, offset, length) {
return blitBuffer(asciiToBytes(string), buf, offset, length)
}

function binaryWrite (buf, string, offset, length) {
function latin1Write (buf, string, offset, length) {
return asciiWrite(buf, string, offset, length)
}

Expand Down Expand Up @@ -938,8 +1013,9 @@ Buffer.prototype.write = function write (string, offset, length, encoding) {
case 'ascii':
return asciiWrite(this, string, offset, length)

case 'latin1':
case 'binary':
return binaryWrite(this, string, offset, length)
return latin1Write(this, string, offset, length)

case 'base64':
// Warning: maxLength not taken into account in base64Write
Expand Down Expand Up @@ -1080,7 +1156,7 @@ function asciiSlice (buf, start, end) {
return ret
}

function binarySlice (buf, start, end) {
function latin1Slice (buf, start, end) {
var ret = ''
end = Math.min(buf.length, end)

Expand Down Expand Up @@ -2956,6 +3032,12 @@ function httpEtagProvider () {
return itemCache
}

httpEtagService.purgeCaches = function httpEtagPurgeCaches () {
angular.forEach(adaptedCaches, function (cache) {
cache.removeAllItems()
})
}

function processCacheId (cacheId) {
var type = typeof cacheId
var isDefined = type === 'number' || (type === 'string' && !!cacheId)
Expand Down
6 changes: 3 additions & 3 deletions release/angular-http-etag.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release/angular-http-etag.min.map

Large diffs are not rendered by default.

0 comments on commit 55cfced

Please # to comment.