Skip to content

Commit

Permalink
Merge pull request mozilla#9072 from Snuffleupagus/more-stringToBytes
Browse files Browse the repository at this point in the history
Use `stringToBytes` in more places
  • Loading branch information
timvandermeij committed Oct 26, 2017
2 parents ad74f6e + 5e62781 commit c62a193
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/core/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import {
createObjectURL, FormatError, isSpace, shadow, Util
createObjectURL, FormatError, isSpace, shadow, stringToBytes, Util
} from '../shared/util';
import { isDict } from './primitives';
import { JpegImage } from './jpg';
Expand Down Expand Up @@ -109,11 +109,7 @@ var Stream = (function StreamClosure() {

var StringStream = (function StringStreamClosure() {
function StringStream(str) {
var length = str.length;
var bytes = new Uint8Array(length);
for (var n = 0; n < length; ++n) {
bytes[n] = str.charCodeAt(n);
}
let bytes = stringToBytes(str);
Stream.call(this, bytes);
}

Expand Down
8 changes: 2 additions & 6 deletions src/display/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

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

Expand Down

0 comments on commit c62a193

Please sign in to comment.