Browse Source

Merge pull request #9072 from Snuffleupagus/more-stringToBytes

Use `stringToBytes` in more places
Tim van der Meij 8 years ago committed by GitHub
parent
commit
c62a19388a
  1. 8
      src/core/stream.js
  2. 8
      src/display/network.js

8
src/core/stream.js

@ -14,7 +14,7 @@
*/ */
import { import {
createObjectURL, FormatError, isSpace, shadow, Util createObjectURL, FormatError, isSpace, shadow, stringToBytes, Util
} from '../shared/util'; } from '../shared/util';
import { isDict } from './primitives'; import { isDict } from './primitives';
import { JpegImage } from './jpg'; import { JpegImage } from './jpg';
@ -109,11 +109,7 @@ var Stream = (function StreamClosure() {
var StringStream = (function StringStreamClosure() { var StringStream = (function StringStreamClosure() {
function StringStream(str) { function StringStream(str) {
var length = str.length; let bytes = stringToBytes(str);
var bytes = new Uint8Array(length);
for (var n = 0; n < length; ++n) {
bytes[n] = str.charCodeAt(n);
}
Stream.call(this, bytes); Stream.call(this, bytes);
} }

8
src/display/network.js

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { assert, createPromiseCapability } from '../shared/util'; import { assert, createPromiseCapability, stringToBytes } from '../shared/util';
import { import {
createResponseStatusError, validateRangeRequestCapabilities createResponseStatusError, validateRangeRequestCapabilities
} from './network_utils'; } from './network_utils';
@ -48,11 +48,7 @@ function getArrayBuffer(xhr) {
if (typeof data !== 'string') { if (typeof data !== 'string') {
return data; return data;
} }
var length = data.length; let array = stringToBytes(data);
var array = new Uint8Array(length);
for (var i = 0; i < length; i++) {
array[i] = data.charCodeAt(i) & 0xFF;
}
return array.buffer; return array.buffer;
} }

Loading…
Cancel
Save