'Load binary file into an ArrayBuffer using webpack
In the browser, I am trying to load a binary file (loaded using webpack, not via HTTP call) into an ArrayBuffer (which will then be parsed using TypedArrays). I am trying to use webpack asset Modules to pack the binary file with the rest of the browser files, but I haven't found a way to extract that file inside the browser code and construct an ArrayBuffer from it.
I am specifying the packing as follows:
module.exports = {
publicPath: '/some/path/',
configureWebpack: {
module: {
rules: [
{
test: /\.trie$/,
type: 'asset/inline',
generator: {
dataUrl: content => content
}
},
],
},
}
}
and then in my typescript file I am 'loading' the content:
const content = require('./50k.trie');
The Chrome debugger tells me that content is of type 'Buffer' (I thought that as a Node.js data type, not a browser data type):
but from here I haven't found a way to construct/load/create an ArrayBuffer.
Do I need to use a different asset type?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

