Skip to content

Commit ea30e2a

Browse files
committed
fix(arraybuffer-loader): fix binary file bugs
1 parent b7d0009 commit ea30e2a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

lib/arraybuffer-loader.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ module.exports = function (content) {
88
const toArrayBufferPath =
99
loaderUtils.stringifyRequest(this, require.resolve('./to-array-buffer.js'))
1010

11-
const base64Data = typeof content === 'string' ?
12-
new Buffer(content).toString('base64') : content.toString('base64')
11+
const base64Data = content.toString('base64')
1312

1413
return `module.exports = require(${toArrayBufferPath})("${base64Data}")`;
1514
}
15+
16+
module.exports.raw = true

test/arraybuffer-loader.js

+10
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ describe('text files', function () {
1919
expect(text).to.equal('\uD83D\uDE07\n') // :innocent:
2020
})
2121
})
22+
23+
describe('binary files', function () {
24+
it('can bundle binary file', function () {
25+
var buffer = require('arraybuffer!./data/binary.dat')
26+
var binarray = new Uint8Array(buffer)
27+
var array = Array.prototype.slice.call(binarray) // Array.from
28+
29+
expect(array).to.deep.equal([ 0x01, 0x02, 0x04, 0x00 ])
30+
})
31+
})

test/data/binary.dat

4 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)