Configring node js.
This commit is contained in:
57
node_modules/jszip/lib/reader/ArrayReader.js
generated
vendored
Normal file
57
node_modules/jszip/lib/reader/ArrayReader.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
var DataReader = require('./DataReader');
|
||||
var utils = require('../utils');
|
||||
|
||||
function ArrayReader(data) {
|
||||
DataReader.call(this, data);
|
||||
for(var i = 0; i < this.data.length; i++) {
|
||||
data[i] = data[i] & 0xFF;
|
||||
}
|
||||
}
|
||||
utils.inherits(ArrayReader, DataReader);
|
||||
/**
|
||||
* @see DataReader.byteAt
|
||||
*/
|
||||
ArrayReader.prototype.byteAt = function(i) {
|
||||
return this.data[this.zero + i];
|
||||
};
|
||||
/**
|
||||
* @see DataReader.lastIndexOfSignature
|
||||
*/
|
||||
ArrayReader.prototype.lastIndexOfSignature = function(sig) {
|
||||
var sig0 = sig.charCodeAt(0),
|
||||
sig1 = sig.charCodeAt(1),
|
||||
sig2 = sig.charCodeAt(2),
|
||||
sig3 = sig.charCodeAt(3);
|
||||
for (var i = this.length - 4; i >= 0; --i) {
|
||||
if (this.data[i] === sig0 && this.data[i + 1] === sig1 && this.data[i + 2] === sig2 && this.data[i + 3] === sig3) {
|
||||
return i - this.zero;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
/**
|
||||
* @see DataReader.readAndCheckSignature
|
||||
*/
|
||||
ArrayReader.prototype.readAndCheckSignature = function (sig) {
|
||||
var sig0 = sig.charCodeAt(0),
|
||||
sig1 = sig.charCodeAt(1),
|
||||
sig2 = sig.charCodeAt(2),
|
||||
sig3 = sig.charCodeAt(3),
|
||||
data = this.readData(4);
|
||||
return sig0 === data[0] && sig1 === data[1] && sig2 === data[2] && sig3 === data[3];
|
||||
};
|
||||
/**
|
||||
* @see DataReader.readData
|
||||
*/
|
||||
ArrayReader.prototype.readData = function(size) {
|
||||
this.checkOffset(size);
|
||||
if(size === 0) {
|
||||
return [];
|
||||
}
|
||||
var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
|
||||
this.index += size;
|
||||
return result;
|
||||
};
|
||||
module.exports = ArrayReader;
|
||||
116
node_modules/jszip/lib/reader/DataReader.js
generated
vendored
Normal file
116
node_modules/jszip/lib/reader/DataReader.js
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
'use strict';
|
||||
var utils = require('../utils');
|
||||
|
||||
function DataReader(data) {
|
||||
this.data = data; // type : see implementation
|
||||
this.length = data.length;
|
||||
this.index = 0;
|
||||
this.zero = 0;
|
||||
}
|
||||
DataReader.prototype = {
|
||||
/**
|
||||
* Check that the offset will not go too far.
|
||||
* @param {string} offset the additional offset to check.
|
||||
* @throws {Error} an Error if the offset is out of bounds.
|
||||
*/
|
||||
checkOffset: function(offset) {
|
||||
this.checkIndex(this.index + offset);
|
||||
},
|
||||
/**
|
||||
* Check that the specified index will not be too far.
|
||||
* @param {string} newIndex the index to check.
|
||||
* @throws {Error} an Error if the index is out of bounds.
|
||||
*/
|
||||
checkIndex: function(newIndex) {
|
||||
if (this.length < this.zero + newIndex || newIndex < 0) {
|
||||
throw new Error("End of data reached (data length = " + this.length + ", asked index = " + (newIndex) + "). Corrupted zip ?");
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Change the index.
|
||||
* @param {number} newIndex The new index.
|
||||
* @throws {Error} if the new index is out of the data.
|
||||
*/
|
||||
setIndex: function(newIndex) {
|
||||
this.checkIndex(newIndex);
|
||||
this.index = newIndex;
|
||||
},
|
||||
/**
|
||||
* Skip the next n bytes.
|
||||
* @param {number} n the number of bytes to skip.
|
||||
* @throws {Error} if the new index is out of the data.
|
||||
*/
|
||||
skip: function(n) {
|
||||
this.setIndex(this.index + n);
|
||||
},
|
||||
/**
|
||||
* Get the byte at the specified index.
|
||||
* @param {number} i the index to use.
|
||||
* @return {number} a byte.
|
||||
*/
|
||||
byteAt: function(i) {
|
||||
// see implementations
|
||||
},
|
||||
/**
|
||||
* Get the next number with a given byte size.
|
||||
* @param {number} size the number of bytes to read.
|
||||
* @return {number} the corresponding number.
|
||||
*/
|
||||
readInt: function(size) {
|
||||
var result = 0,
|
||||
i;
|
||||
this.checkOffset(size);
|
||||
for (i = this.index + size - 1; i >= this.index; i--) {
|
||||
result = (result << 8) + this.byteAt(i);
|
||||
}
|
||||
this.index += size;
|
||||
return result;
|
||||
},
|
||||
/**
|
||||
* Get the next string with a given byte size.
|
||||
* @param {number} size the number of bytes to read.
|
||||
* @return {string} the corresponding string.
|
||||
*/
|
||||
readString: function(size) {
|
||||
return utils.transformTo("string", this.readData(size));
|
||||
},
|
||||
/**
|
||||
* Get raw data without conversion, <size> bytes.
|
||||
* @param {number} size the number of bytes to read.
|
||||
* @return {Object} the raw data, implementation specific.
|
||||
*/
|
||||
readData: function(size) {
|
||||
// see implementations
|
||||
},
|
||||
/**
|
||||
* Find the last occurence of a zip signature (4 bytes).
|
||||
* @param {string} sig the signature to find.
|
||||
* @return {number} the index of the last occurence, -1 if not found.
|
||||
*/
|
||||
lastIndexOfSignature: function(sig) {
|
||||
// see implementations
|
||||
},
|
||||
/**
|
||||
* Read the signature (4 bytes) at the current position and compare it with sig.
|
||||
* @param {string} sig the expected signature
|
||||
* @return {boolean} true if the signature matches, false otherwise.
|
||||
*/
|
||||
readAndCheckSignature: function(sig) {
|
||||
// see implementations
|
||||
},
|
||||
/**
|
||||
* Get the next date.
|
||||
* @return {Date} the date.
|
||||
*/
|
||||
readDate: function() {
|
||||
var dostime = this.readInt(4);
|
||||
return new Date(Date.UTC(
|
||||
((dostime >> 25) & 0x7f) + 1980, // year
|
||||
((dostime >> 21) & 0x0f) - 1, // month
|
||||
(dostime >> 16) & 0x1f, // day
|
||||
(dostime >> 11) & 0x1f, // hour
|
||||
(dostime >> 5) & 0x3f, // minute
|
||||
(dostime & 0x1f) << 1)); // second
|
||||
}
|
||||
};
|
||||
module.exports = DataReader;
|
||||
19
node_modules/jszip/lib/reader/NodeBufferReader.js
generated
vendored
Normal file
19
node_modules/jszip/lib/reader/NodeBufferReader.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
var Uint8ArrayReader = require('./Uint8ArrayReader');
|
||||
var utils = require('../utils');
|
||||
|
||||
function NodeBufferReader(data) {
|
||||
Uint8ArrayReader.call(this, data);
|
||||
}
|
||||
utils.inherits(NodeBufferReader, Uint8ArrayReader);
|
||||
|
||||
/**
|
||||
* @see DataReader.readData
|
||||
*/
|
||||
NodeBufferReader.prototype.readData = function(size) {
|
||||
this.checkOffset(size);
|
||||
var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
|
||||
this.index += size;
|
||||
return result;
|
||||
};
|
||||
module.exports = NodeBufferReader;
|
||||
38
node_modules/jszip/lib/reader/StringReader.js
generated
vendored
Normal file
38
node_modules/jszip/lib/reader/StringReader.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
var DataReader = require('./DataReader');
|
||||
var utils = require('../utils');
|
||||
|
||||
function StringReader(data) {
|
||||
DataReader.call(this, data);
|
||||
}
|
||||
utils.inherits(StringReader, DataReader);
|
||||
/**
|
||||
* @see DataReader.byteAt
|
||||
*/
|
||||
StringReader.prototype.byteAt = function(i) {
|
||||
return this.data.charCodeAt(this.zero + i);
|
||||
};
|
||||
/**
|
||||
* @see DataReader.lastIndexOfSignature
|
||||
*/
|
||||
StringReader.prototype.lastIndexOfSignature = function(sig) {
|
||||
return this.data.lastIndexOf(sig) - this.zero;
|
||||
};
|
||||
/**
|
||||
* @see DataReader.readAndCheckSignature
|
||||
*/
|
||||
StringReader.prototype.readAndCheckSignature = function (sig) {
|
||||
var data = this.readData(4);
|
||||
return sig === data;
|
||||
};
|
||||
/**
|
||||
* @see DataReader.readData
|
||||
*/
|
||||
StringReader.prototype.readData = function(size) {
|
||||
this.checkOffset(size);
|
||||
// this will work because the constructor applied the "& 0xff" mask.
|
||||
var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
|
||||
this.index += size;
|
||||
return result;
|
||||
};
|
||||
module.exports = StringReader;
|
||||
22
node_modules/jszip/lib/reader/Uint8ArrayReader.js
generated
vendored
Normal file
22
node_modules/jszip/lib/reader/Uint8ArrayReader.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
var ArrayReader = require('./ArrayReader');
|
||||
var utils = require('../utils');
|
||||
|
||||
function Uint8ArrayReader(data) {
|
||||
ArrayReader.call(this, data);
|
||||
}
|
||||
utils.inherits(Uint8ArrayReader, ArrayReader);
|
||||
/**
|
||||
* @see DataReader.readData
|
||||
*/
|
||||
Uint8ArrayReader.prototype.readData = function(size) {
|
||||
this.checkOffset(size);
|
||||
if(size === 0) {
|
||||
// in IE10, when using subarray(idx, idx), we get the array [0x00] instead of [].
|
||||
return new Uint8Array(0);
|
||||
}
|
||||
var result = this.data.subarray(this.zero + this.index, this.zero + this.index + size);
|
||||
this.index += size;
|
||||
return result;
|
||||
};
|
||||
module.exports = Uint8ArrayReader;
|
||||
28
node_modules/jszip/lib/reader/readerFor.js
generated
vendored
Normal file
28
node_modules/jszip/lib/reader/readerFor.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('../utils');
|
||||
var support = require('../support');
|
||||
var ArrayReader = require('./ArrayReader');
|
||||
var StringReader = require('./StringReader');
|
||||
var NodeBufferReader = require('./NodeBufferReader');
|
||||
var Uint8ArrayReader = require('./Uint8ArrayReader');
|
||||
|
||||
/**
|
||||
* Create a reader adapted to the data.
|
||||
* @param {String|ArrayBuffer|Uint8Array|Buffer} data the data to read.
|
||||
* @return {DataReader} the data reader.
|
||||
*/
|
||||
module.exports = function (data) {
|
||||
var type = utils.getTypeOf(data);
|
||||
utils.checkSupport(type);
|
||||
if (type === "string" && !support.uint8array) {
|
||||
return new StringReader(data);
|
||||
}
|
||||
if (type === "nodebuffer") {
|
||||
return new NodeBufferReader(data);
|
||||
}
|
||||
if (support.uint8array) {
|
||||
return new Uint8ArrayReader(utils.transformTo("uint8array", data));
|
||||
}
|
||||
return new ArrayReader(utils.transformTo("array", data));
|
||||
};
|
||||
Reference in New Issue
Block a user