Skip to content

Commit

Permalink
Convert buffer to UInt32Array GH-5
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Evans <[email protected]>
  • Loading branch information
mrbrianevans authored and sanjayaksaxena committed Feb 7, 2022
1 parent c99c545 commit e153b02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/read-core-model.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/read-core-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

const originalModel = require( './languages/cur/models/eng-core-web-model.json' );

/**
* @param {string} data - base64 string of data to be converted
* @returns {ArrayBuffer} an ArrayBuffer of the data
*/
const bufferFromBase64 = function ( data ) {
const decodedData = atob( data );
var size = decodedData.length;
Expand All @@ -44,7 +48,7 @@ const bufferFromBase64 = function ( data ) {
bytes[ k ] = decodedData.charCodeAt( k );
}

return bytes;
return bytes.buffer;
}; // bufferFromBase64()

var readModel = function ( ) {
Expand All @@ -57,9 +61,9 @@ var readModel = function ( ) {
var featuresData = model.features;
var pos = model.pos;
// Read the lexicon block.
model.lexicon = bufferFromBase64(model.lexicon);
model.lexicon = new Uint32Array(bufferFromBase64(model.lexicon));

model.xpansions = bufferFromBase64(model.xpansions);
model.xpansions = new Uint32Array(bufferFromBase64(model.xpansions));

// Rebuild hash from list for the required features.
for ( const f in model.packing.layout ) {
Expand Down

0 comments on commit e153b02

Please sign in to comment.