import * as Token from 'token-types' ; import * as util from '../common/Util' ; import { DataType } from './AsfObject' ; export type AttributeParser = ( buf : Buffer ) => boolean | string | number | bigint | Buffer ; export class AsfUtil { public static getParserForAttr ( i ) { return AsfUtil . attributeParsers [ i ] ; } public static parseUnicodeAttr ( buf ) { return util . stripNulls ( util . decodeString ( buf , 'utf16le' ) ) ; } private static attributeParsers : AttributeParser [ ] = [ AsfUtil . parseUnicodeAttr , AsfUtil . parseByteArrayAttr , AsfUtil . parseBoolAttr , AsfUtil . parseDWordAttr , AsfUtil . parseQWordAttr , AsfUtil . parseWordAttr , AsfUtil . parseByteArrayAttr ] ; private static parseByteArrayAttr ( buf ) { const newBuf = Buffer . alloc ( buf . length ) ; buf . copy ( newBuf ) ; return newBuf ; } private static parseBoolAttr ( buf , offset = 0 ) { return AsfUtil . parseWordAttr ( buf , offset ) === 1 ; } private static parseDWordAttr ( buf , offset = 0 ) { return buf . readUInt32LE ( offset ) ; } private static parseQWordAttr ( buf , offset = 0 ) { return Token . UINT64_LE . get ( buf , offset ) ; } private static parseWordAttr ( buf , offset = 0 ) { return buf . readUInt16LE ( offset ) ; } }