forked from 0x2620/oxjs
rather use ''.slice than ''.substr
This commit is contained in:
parent
f990f3b857
commit
1608664bb6
20 changed files with 69 additions and 71 deletions
|
|
@ -204,14 +204,14 @@
|
|||
// bytes IHDR name), keep bytes 16 to 19 (width), discard bytes 20 to 29
|
||||
// (4 bytes height, 5 bytes flags), keep bytes 29 to 32 (IHDR checksum),
|
||||
// keep the rest (IDAT chunks), discard the last 12 bytes (IEND chunk).
|
||||
data = str.substr(16, 4) + str.substr(29, 4);
|
||||
idat = str.substr(33, str.length - 45);
|
||||
data = str.slice(16, 20) + str.slice(29, 33);
|
||||
idat = str.slice(33, -45);
|
||||
while (idat) {
|
||||
// Each IDAT chunk is 4 bytes length, 4 bytes name, length bytes
|
||||
// data and 4 bytes checksum. We can discard the name parts.
|
||||
len = idat.substr(0, 4);
|
||||
data += len + idat.substr(8, 4 + (len = Ox.decodeBase256(len)));
|
||||
idat = idat.substr(12 + len);
|
||||
len = idat.slice(0, 4);
|
||||
data += len + idat.slice(8, 12 + (len = Ox.decodeBase256(len)));
|
||||
idat = idat.slice(12 + len);
|
||||
}
|
||||
callback && callback(data);
|
||||
return data;
|
||||
|
|
@ -234,18 +234,18 @@
|
|||
var image = new Image(),
|
||||
// PNG file signature and IHDR chunk
|
||||
data = '\u0089PNG\r\n\u001A\n\u0000\u0000\u0000\u000DIHDR'
|
||||
+ str.substr(0, 4) + '\u0000\u0000\u0000\u0001'
|
||||
+ '\u0008\u0006\u0000\u0000\u0000' + str.substr(4, 4),
|
||||
+ str.slice(0, 4) + '\u0000\u0000\u0000\u0001'
|
||||
+ '\u0008\u0006\u0000\u0000\u0000' + str.slice(4, 8),
|
||||
// IDAT chunks
|
||||
idat = str.substr(8), len;
|
||||
idat = str.slice(8), len;
|
||||
function error() {
|
||||
throw new RangeError('Deflate codec can\'t decode data.');
|
||||
}
|
||||
while (idat) {
|
||||
// Reinsert the IDAT chunk names
|
||||
len = idat.substr(0, 4);
|
||||
data += len + 'IDAT' + idat.substr(4, 4 + (len = Ox.decodeBase256(len)));
|
||||
idat = idat.substr(8 + len);
|
||||
len = idat.slice(0, 4);
|
||||
data += len + 'IDAT' + idat.slice(4, 8 + (len = Ox.decodeBase256(len)));
|
||||
idat = idat.slice(8 + len);
|
||||
}
|
||||
// IEND chunk
|
||||
data += '\u0000\u0000\u0000\u0000IEND\u00AE\u0042\u0060\u0082';
|
||||
|
|
@ -259,7 +259,7 @@
|
|||
try {
|
||||
// Parse the first byte as number of bytes to chop at the end,
|
||||
// and the rest, without these bytes, as an UTF8-encoded string.
|
||||
str = Ox.decodeUTF8(str.substr(1, str.length - 1 - str.charCodeAt(0)))
|
||||
str = Ox.decodeUTF8(str.slice(1, -str.CharCodeAt(0)));
|
||||
} catch (e) {
|
||||
error();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue