Add isWasm util (#673)
This commit is contained in:
@@ -27,3 +27,4 @@ export { default as isToBn } from './toBn';
|
||||
export { default as isU8a } from './u8a';
|
||||
export { default as isUndefined } from './undefined';
|
||||
export { default as isUtf8 } from './utf8';
|
||||
export { default as isWasm } from './wasm';
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2017-2020 @polkadot/util authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import u8aEq from '../u8a/eq';
|
||||
|
||||
const WASM_MAGIC = new Uint8Array([0, 97, 115, 109]); // \0asm
|
||||
|
||||
/**
|
||||
* @name isWasm
|
||||
* @summary Tests if the input has a WASM header
|
||||
* @description
|
||||
* Checks to see if the input Uint8Array contains a valid WASM header
|
||||
*/
|
||||
export default function isWasm (value?: Uint8Array): boolean {
|
||||
return !!value && u8aEq(value.subarray(0, 4), WASM_MAGIC);
|
||||
}
|
||||
Reference in New Issue
Block a user