Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions lib/node_modules/@stdlib/fs/read-wasm/lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

// MODULES //

var isObject = require( '@stdlib/assert/is-plain-object' );
var isFunction = require( '@stdlib/assert/is-function' );
var isUint8Array = require( '@stdlib/assert/is-uint8array' );
var readFile = require( '@stdlib/fs/read-file' );
var Uint8Array = require( '@stdlib/array/uint8' );
var format = require( '@stdlib/string/format' );
var isObject = require('@stdlib/assert/is-plain-object');
var isFunction = require('@stdlib/assert/is-function');
var isUint8Array = require('@stdlib/assert/is-uint8array');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure you use eslint fix to correctly format this file .

var readFile = require('@stdlib/fs/read-file');
var Uint8Array = require('@stdlib/array/uint8');
var format = require('@stdlib/string/format');


// MAIN //
Expand All @@ -40,39 +40,40 @@ var format = require( '@stdlib/string/format' );
* @throws {TypeError} options argument must be an object
* @throws {TypeError} callback argument must be a function
*
* /* eslint-disable-next-line stdlib/jsdoc-doctest */
* @example
* var join = require( 'path' ).join;
* var instanceOf = require( '@stdlib/assert/instance-of' );
* var join = require('path').join;
* var instanceOf = require('@stdlib/assert/instance-of');
*
* var fpath = join( __dirname, 'foo.wasm' );
* readWASM( fpath, onRead );
* var fpath = join(__dirname, 'foo.wasm');
* readWASM(fpath, onRead);
*
* function onRead( error, buf ) {
* if ( error ) {
* function onRead(error, buf) {
* if (error) {
* throw error;
* }
* console.log( buf );
* console.log(buf);
* }
*/
function readWASM( file, options, clbk ) {
*/
function readWASM(file, options, clbk) {
var opts;
var done;
if ( arguments.length < 3 ) {
if (arguments.length < 3) {
opts = {};
done = options;
} else {
if ( !isObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
if (!isObject(options)) {
throw new TypeError(format('invalid argument. Options argument must be an object. Value: `%s`.', options));
}
opts = options;
done = clbk;
}
if ( !isFunction( done ) ) {
throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', done ) );
if (!isFunction(done)) {
throw new TypeError(format('invalid argument. Callback argument must be a function. Value: `%s`.', done));
}
// Always override setting the encoding option, as wasm is a binary file format:
opts.encoding = null;
readFile( file, opts, onRead );
readFile(file, opts, onRead);

/**
* Callback invoked upon reading a file.
Expand All @@ -82,21 +83,21 @@ function readWASM( file, options, clbk ) {
* @param {(Buffer|string)} file - file contents
* @returns {void}
*/
function onRead( error, file ) {
function onRead(error, file) {
var out;
var i;
if ( error ) {
return done( error );
if (error) {
return done(error);
}
if ( isUint8Array( file ) ) {
return done( null, file );
if (isUint8Array(file)) {
return done(null, file);
}
// Handle older Node.js environments where Buffer objects are not Uint8Arrays...
out = new Uint8Array( file.length );
for ( i = 0; i < file.length; i++ ) {
out[ i ] = file[ i ];
out = new Uint8Array(file.length);
for (i = 0; i < file.length; i++) {
out[i] = file[i];
}
done( null, out );
done(null, out);
}
}

Expand Down
40 changes: 21 additions & 19 deletions lib/node_modules/@stdlib/fs/read-wasm/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,45 @@
*
* @module @stdlib/fs/read-wasm
*
* /* eslint-disable-next-line stdlib/jsdoc-doctest */
* @example
* var join = require( 'path' ).join;
* var readWASM = require( '@stdlib/fs/read-wasm' );
* var join = require('path').join;
* var readWASM = require('@stdlib/fs/read-wasm');
*
* var fpath = join( __dirname, 'foo.wasm' );
* readWASM( fpath, onRead );
* var fpath = join(__dirname, 'foo.wasm');
* readWASM(fpath, onRead);
*
* function onRead( error, buf ) {
* if ( error ) {
* function onRead(error, buf) {
* if (error) {
* throw error;
* }
* console.log( out );
* console.log(out);
* }
*
*
* /* eslint-disable-next-line stdlib/jsdoc-doctest */
* @example
* var join = require( 'path' ).join;
* var instanceOf = require( '@stdlib/assert/instance-of' );
* var readWASMSync = require( '@stdlib/fs/read-wasm' ).sync;
* var join = require('path').join;
* var instanceOf = require('@stdlib/assert/instance-of');
* var readWASMSync = require('@stdlib/fs/read-wasm').sync;
*
* var fpath = join( __dirname, 'foo.wasm' );
* var out = readWASMSync( fpath );
* if ( instanceOf( out, Error ) ) {
* var fpath = join(__dirname, 'foo.wasm');
* var out = readWASMSync(fpath);
* if (instanceOf(out, Error)) {
* throw out;
* }
* console.log( out );
* console.log(out);
*/

// MODULES //

var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
var readWASM = require( './async.js' );
var sync = require( './sync.js' );
var setReadOnly = require('@stdlib/utils/define-nonenumerable-read-only-property');
var readWASM = require('./async.js');
var sync = require('./sync.js');


// MAIN //

setReadOnly( readWASM, 'sync', sync );
setReadOnly(readWASM, 'sync', sync);


// EXPORTS //
Expand Down
45 changes: 23 additions & 22 deletions lib/node_modules/@stdlib/fs/read-wasm/lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

// MODULES //

var isObject = require( '@stdlib/assert/is-plain-object' );
var isUint8Array = require( '@stdlib/assert/is-uint8array' );
var instanceOf = require( '@stdlib/assert/instance-of' );
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
var Uint8Array = require( '@stdlib/array/uint8' );
var format = require( '@stdlib/string/format' );
var isObject = require('@stdlib/assert/is-plain-object');
var isUint8Array = require('@stdlib/assert/is-uint8array');
var instanceOf = require('@stdlib/assert/instance-of');
var readFileSync = require('@stdlib/fs/read-file').sync;
var Uint8Array = require('@stdlib/array/uint8');
var format = require('@stdlib/string/format');


// MAIN //
Expand All @@ -39,43 +39,44 @@ var format = require( '@stdlib/string/format' );
* @throws {TypeError} options argument must be an object
* @returns {(Uint8Array|Error)} file contents or an error
*
* /* eslint-disable-next-line stdlib/jsdoc-doctest */
* @example
* var join = require( 'path' ).join;
* var instanceOf = require( '@stdlib/assert/instance-of' );
* var join = require('path').join;
* var instanceOf = require('@stdlib/assert/instance-of');
*
* var fpath = join( __dirname, 'foo.wasm' );
* var out = readWASMSync( fpath );
* if ( instanceOf( out, Error ) ) {
* var fpath = join(__dirname, 'foo.wasm');
* var out = readWASMSync(fpath);
* if (instanceOf(out, Error)) {
* throw out;
* }
* console.log( out );
* console.log(out);
*/
function readWASMSync( file, options ) {
function readWASMSync(file, options) {
var opts;
var out;
var f;
var i;
if ( arguments.length > 1 ) {
if ( !isObject( options ) ) {
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
if (arguments.length > 1) {
if (!isObject(options)) {
throw new TypeError(format('invalid argument. Options argument must be an object. Value: `%s`.', options));
}
opts = options;
} else {
opts = {};
}
// Always override setting the encoding option, as wasm is a binary file format:
opts.encoding = null;
f = readFileSync( file, opts );
if ( instanceOf( f, Error ) ) {
f = readFileSync(file, opts);
if (instanceOf(f, Error)) {
return f;
}
if ( isUint8Array( f ) ) {
if (isUint8Array(f)) {
return f;
}
// Handle older Node.js environments where Buffer objects are not Uint8Arrays...
out = new Uint8Array( f.length );
for ( i = 0; i < f.length; i++ ) {
out[ i ] = f[ i ];
out = new Uint8Array(f.length);
for (i = 0; i < f.length; i++) {
out[i] = f[i];
}
return out;
}
Expand Down
Loading
Loading