2017-09-30 06:18:11 +00:00
function read _double _le ( b /*:RawBytes|CFBlob*/ , idx /*:number*/ ) /*:number*/ {
2017-02-10 19:23:01 +00:00
var s = 1 - 2 * ( b [ idx + 7 ] >>> 7 ) ;
var e = ( ( b [ idx + 7 ] & 0x7f ) << 4 ) + ( ( b [ idx + 6 ] >>> 4 ) & 0x0f ) ;
var m = ( b [ idx + 6 ] & 0x0f ) ;
for ( var i = 5 ; i >= 0 ; -- i ) m = m * 256 + b [ idx + i ] ;
2018-02-08 18:21:39 +00:00
if ( e == 0x7ff ) return m == 0 ? ( s * Infinity ) : NaN ;
2017-02-10 19:23:01 +00:00
if ( e == 0 ) e = - 1022 ;
else { e -= 1023 ; m += Math . pow ( 2 , 52 ) ; }
return s * Math . pow ( 2 , e - 52 ) * m ;
}
2017-09-30 06:18:11 +00:00
function write _double _le ( b /*:RawBytes|CFBlob*/ , v /*:number*/ , idx /*:number*/ ) {
2018-02-08 18:21:39 +00:00
var bs = ( ( ( ( v < 0 ) || ( 1 / v == - Infinity ) ) ? 1 : 0 ) << 7 ) , e = 0 , m = 0 ;
var av = bs ? ( - v ) : v ;
2017-02-10 19:23:01 +00:00
if ( ! isFinite ( av ) ) { e = 0x7ff ; m = isNaN ( v ) ? 0x6969 : 0 ; }
2017-09-22 22:18:51 +00:00
else if ( av == 0 ) e = m = 0 ;
2017-02-10 19:23:01 +00:00
else {
2017-09-05 05:26:50 +00:00
e = Math . floor ( Math . log ( av ) / Math . LN2 ) ;
m = av * Math . pow ( 2 , 52 - e ) ;
2018-02-08 18:21:39 +00:00
if ( ( e <= - 1023 ) && ( ! isFinite ( m ) || ( m < Math . pow ( 2 , 52 ) ) ) ) { e = - 1022 ; }
2017-02-10 19:23:01 +00:00
else { m -= Math . pow ( 2 , 52 ) ; e += 1023 ; }
}
for ( var i = 0 ; i <= 5 ; ++ i , m /= 256 ) b [ idx + i ] = m & 0xff ;
2018-02-08 18:21:39 +00:00
b [ idx + 6 ] = ( ( e & 0x0f ) << 4 ) | ( m & 0xf ) ;
2017-02-10 19:23:01 +00:00
b [ idx + 7 ] = ( e >> 4 ) | bs ;
2014-01-28 16:38:02 +00:00
}
2018-02-21 07:01:34 +00:00
var _ _toBuffer = function ( bufs /*:Array<Array<RawBytes> >*/ ) /*:RawBytes*/ { var x = [ ] , w = 10240 ; for ( var i = 0 ; i < bufs [ 0 ] . length ; ++ i ) if ( bufs [ 0 ] [ i ] ) for ( var j = 0 , L = bufs [ 0 ] [ i ] . length ; j < L ; j += w ) x . push . apply ( x , bufs [ 0 ] [ i ] . slice ( j , j + w ) ) ; return x ; } ;
2017-09-30 06:18:11 +00:00
var _ _ _toBuffer = _ _toBuffer ;
2017-10-02 08:15:36 +00:00
var _ _utf16le = function ( b /*:RawBytes|CFBlob*/ , s /*:number*/ , e /*:number*/ ) /*:string*/ { var ss /*:Array<string>*/ = [ ] ; for ( var i = s ; i < e ; i += 2 ) ss . push ( String . fromCharCode ( _ _readUInt16LE ( b , i ) ) ) ; return ss . join ( "" ) . replace ( chr0 , '' ) ; } ;
2017-09-30 06:18:11 +00:00
var _ _ _utf16le = _ _utf16le ;
2017-08-19 23:06:34 +00:00
var _ _hexlify = function ( b /*:RawBytes|CFBlob*/ , s /*:number*/ , l /*:number*/ ) /*:string*/ { var ss /*:Array<string>*/ = [ ] ; for ( var i = s ; i < s + l ; ++ i ) ss . push ( ( "0" + b [ i ] . toString ( 16 ) ) . slice ( - 2 ) ) ; return ss . join ( "" ) ; } ;
var _ _ _hexlify = _ _hexlify ;
2017-09-30 06:18:11 +00:00
var _ _utf8 = function ( b /*:RawBytes|CFBlob*/ , s /*:number*/ , e /*:number*/ ) { var ss = [ ] ; for ( var i = s ; i < e ; i ++ ) ss . push ( String . fromCharCode ( _ _readUInt8 ( b , i ) ) ) ; return ss . join ( "" ) ; } ;
2018-02-18 03:56:52 +00:00
var _ _ _utf8 = _ _utf8 ;
2017-09-30 06:18:11 +00:00
var _ _lpstr = function ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = _ _readUInt32LE ( b , i ) ; return len > 0 ? _ _utf8 ( b , i + 4 , i + 4 + len - 1 ) : "" ; } ;
var _ _ _lpstr = _ _lpstr ;
2017-12-30 05:40:35 +00:00
var _ _cpstr = function ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = _ _readUInt32LE ( b , i ) ; return len > 0 ? _ _utf8 ( b , i + 4 , i + 4 + len - 1 ) : "" ; } ;
var _ _ _cpstr = _ _cpstr ;
2017-09-30 06:18:11 +00:00
var _ _lpwstr = function ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = 2 * _ _readUInt32LE ( b , i ) ; return len > 0 ? _ _utf8 ( b , i + 4 , i + 4 + len - 1 ) : "" ; } ;
var _ _ _lpwstr = _ _lpwstr ;
2017-04-13 01:29:38 +00:00
var _ _lpp4 , _ _ _lpp4 ;
2017-09-30 06:18:11 +00:00
_ _lpp4 = _ _ _lpp4 = function lpp4 _ ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = _ _readUInt32LE ( b , i ) ; return len > 0 ? _ _utf16le ( b , i + 4 , i + 4 + len ) : "" ; } ;
var _ _8lpp4 = function ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = _ _readUInt32LE ( b , i ) ; return len > 0 ? _ _utf8 ( b , i + 4 , i + 4 + len ) : "" ; } ;
var _ _ _8lpp4 = _ _8lpp4 ;
2014-07-28 13:22:32 +00:00
var _ _double , _ _ _double ;
2017-09-30 06:18:11 +00:00
_ _double = _ _ _double = function ( b /*:RawBytes|CFBlob*/ , idx /*:number*/ ) { return read _double _le ( b , idx ) ; } ;
2022-02-10 12:40:50 +00:00
var is _buf = function is _buf _a ( a ) { return Array . isArray ( a ) || ( typeof Uint8Array !== "undefined" && a instanceof Uint8Array ) ; } ;
2017-09-30 06:18:11 +00:00
if ( has _buf /*:: && typeof Buffer !== 'undefined'*/ ) {
2017-10-02 08:15:36 +00:00
_ _utf16le = function ( b /*:RawBytes|CFBlob*/ , s /*:number*/ , e /*:number*/ ) /*:string*/ { if ( ! Buffer . isBuffer ( b ) /*:: || !(b instanceof Buffer)*/ ) return _ _ _utf16le ( b , s , e ) ; return b . toString ( 'utf16le' , s , e ) . replace ( chr0 , '' ) /*.replace(chr1,'!')*/ ; } ;
2017-09-30 06:18:11 +00:00
_ _hexlify = function ( b /*:RawBytes|CFBlob*/ , s /*:number*/ , l /*:number*/ ) /*:string*/ { return Buffer . isBuffer ( b ) /*:: && b instanceof Buffer*/ ? b . toString ( 'hex' , s , s + l ) : _ _ _hexlify ( b , s , l ) ; } ;
_ _lpstr = function lpstr _b ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { if ( ! Buffer . isBuffer ( b ) /*:: || !(b instanceof Buffer)*/ ) return _ _ _lpstr ( b , i ) ; var len = b . readUInt32LE ( i ) ; return len > 0 ? b . toString ( 'utf8' , i + 4 , i + 4 + len - 1 ) : "" ; } ;
2017-12-30 05:40:35 +00:00
_ _cpstr = function cpstr _b ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { if ( ! Buffer . isBuffer ( b ) /*:: || !(b instanceof Buffer)*/ ) return _ _ _cpstr ( b , i ) ; var len = b . readUInt32LE ( i ) ; return len > 0 ? b . toString ( 'utf8' , i + 4 , i + 4 + len - 1 ) : "" ; } ;
2017-09-30 06:18:11 +00:00
_ _lpwstr = function lpwstr _b ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { if ( ! Buffer . isBuffer ( b ) /*:: || !(b instanceof Buffer)*/ ) return _ _ _lpwstr ( b , i ) ; var len = 2 * b . readUInt32LE ( i ) ; return b . toString ( 'utf16le' , i + 4 , i + 4 + len - 1 ) ; } ;
_ _lpp4 = function lpp4 _b ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { if ( ! Buffer . isBuffer ( b ) /*:: || !(b instanceof Buffer)*/ ) return _ _ _lpp4 ( b , i ) ; var len = b . readUInt32LE ( i ) ; return b . toString ( 'utf16le' , i + 4 , i + 4 + len ) ; } ;
_ _8lpp4 = function lpp4 _8b ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { if ( ! Buffer . isBuffer ( b ) /*:: || !(b instanceof Buffer)*/ ) return _ _ _8lpp4 ( b , i ) ; var len = b . readUInt32LE ( i ) ; return b . toString ( 'utf8' , i + 4 , i + 4 + len ) ; } ;
2018-02-18 03:56:52 +00:00
_ _utf8 = function utf8 _b ( b /*:RawBytes|CFBlob*/ , s /*:number*/ , e /*:number*/ ) { return ( Buffer . isBuffer ( b ) /*:: && (b instanceof Buffer)*/ ) ? b . toString ( 'utf8' , s , e ) : _ _ _utf8 ( b , s , e ) ; } ;
2022-02-10 12:40:50 +00:00
_ _toBuffer = function ( bufs ) { return ( bufs [ 0 ] . length > 0 && Buffer . isBuffer ( bufs [ 0 ] [ 0 ] ) ) ? Buffer . concat ( bufs [ 0 ] . map ( function ( x ) { return Buffer . isBuffer ( x ) ? x : Buffer _from ( x ) ; } ) ) : _ _ _toBuffer ( bufs ) ; } ;
bconcat = function ( bufs ) { return Buffer . concat ( bufs . map ( function ( buf ) { return Buffer . isBuffer ( buf ) ? buf : Buffer _from ( buf ) ; } ) ) ; } ;
2017-09-30 06:18:11 +00:00
_ _double = function double _ ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { if ( Buffer . isBuffer ( b ) /*::&& b instanceof Buffer*/ ) return b . readDoubleLE ( i ) ; return _ _ _double ( b , i ) ; } ;
2022-02-10 12:40:50 +00:00
is _buf = function is _buf _b ( a ) { return Buffer . isBuffer ( a ) || Array . isArray ( a ) || ( typeof Uint8Array !== "undefined" && a instanceof Uint8Array ) ; } ;
2014-01-28 16:38:02 +00:00
}
2015-04-02 20:32:22 +00:00
/* from js-xls */
2022-02-13 09:35:34 +00:00
function cpdoit ( ) {
2022-03-11 05:29:05 +00:00
_ _utf16le = function ( b /*:RawBytes|CFBlob*/ , s /*:number*/ , e /*:number*/ ) { return $cptable . utils . decode ( 1200 , b . slice ( s , e ) ) . replace ( chr0 , '' ) ; } ;
_ _utf8 = function ( b /*:RawBytes|CFBlob*/ , s /*:number*/ , e /*:number*/ ) { return $cptable . utils . decode ( 65001 , b . slice ( s , e ) ) ; } ;
_ _lpstr = function ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = _ _readUInt32LE ( b , i ) ; return len > 0 ? $cptable . utils . decode ( current _ansi , b . slice ( i + 4 , i + 4 + len - 1 ) ) : "" ; } ;
_ _cpstr = function ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = _ _readUInt32LE ( b , i ) ; return len > 0 ? $cptable . utils . decode ( current _codepage , b . slice ( i + 4 , i + 4 + len - 1 ) ) : "" ; } ;
_ _lpwstr = function ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = 2 * _ _readUInt32LE ( b , i ) ; return len > 0 ? $cptable . utils . decode ( 1200 , b . slice ( i + 4 , i + 4 + len - 1 ) ) : "" ; } ;
_ _lpp4 = function ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = _ _readUInt32LE ( b , i ) ; return len > 0 ? $cptable . utils . decode ( 1200 , b . slice ( i + 4 , i + 4 + len ) ) : "" ; } ;
_ _8lpp4 = function ( b /*:RawBytes|CFBlob*/ , i /*:number*/ ) { var len = _ _readUInt32LE ( b , i ) ; return len > 0 ? $cptable . utils . decode ( 65001 , b . slice ( i + 4 , i + 4 + len ) ) : "" ; } ;
2015-04-02 20:32:22 +00:00
}
2022-03-11 05:29:05 +00:00
if ( typeof $cptable !== 'undefined' ) cpdoit ( ) ;
2014-06-29 18:29:45 +00:00
2017-09-30 06:18:11 +00:00
var _ _readUInt8 = function ( b /*:RawBytes|CFBlob*/ , idx /*:number*/ ) /*:number*/ { return b [ idx ] ; } ;
2018-02-08 18:21:39 +00:00
var _ _readUInt16LE = function ( b /*:RawBytes|CFBlob*/ , idx /*:number*/ ) /*:number*/ { return ( b [ idx + 1 ] * ( 1 << 8 ) ) + b [ idx ] ; } ;
var _ _readInt16LE = function ( b /*:RawBytes|CFBlob*/ , idx /*:number*/ ) /*:number*/ { var u = ( b [ idx + 1 ] * ( 1 << 8 ) ) + b [ idx ] ; return ( u < 0x8000 ) ? u : ( ( 0xffff - u + 1 ) * - 1 ) ; } ;
2017-09-30 06:18:11 +00:00
var _ _readUInt32LE = function ( b /*:RawBytes|CFBlob*/ , idx /*:number*/ ) /*:number*/ { return b [ idx + 3 ] * ( 1 << 24 ) + ( b [ idx + 2 ] << 16 ) + ( b [ idx + 1 ] << 8 ) + b [ idx ] ; } ;
var _ _readInt32LE = function ( b /*:RawBytes|CFBlob*/ , idx /*:number*/ ) /*:number*/ { return ( b [ idx + 3 ] << 24 ) | ( b [ idx + 2 ] << 16 ) | ( b [ idx + 1 ] << 8 ) | b [ idx ] ; } ;
2017-10-17 00:14:32 +00:00
var _ _readInt32BE = function ( b /*:RawBytes|CFBlob*/ , idx /*:number*/ ) /*:number*/ { return ( b [ idx ] << 24 ) | ( b [ idx + 1 ] << 16 ) | ( b [ idx + 2 ] << 8 ) | b [ idx + 3 ] ; } ;
2014-01-28 16:38:02 +00:00
2017-09-30 06:18:11 +00:00
function ReadShift ( size /*:number*/ , t /*:?string*/ ) /*:number|string*/ {
var o = "" , oI /*:: :number = 0*/ , oR , oo = [ ] , w , vv , i , loc ;
2015-04-02 20:32:22 +00:00
switch ( t ) {
case 'dbcs' :
loc = this . l ;
if ( has _buf && Buffer . isBuffer ( this ) ) o = this . slice ( this . l , this . l + 2 * size ) . toString ( "utf16le" ) ;
2018-02-08 18:21:39 +00:00
else for ( i = 0 ; i < size ; ++ i ) { o += String . fromCharCode ( _ _readUInt16LE ( this , loc ) ) ; loc += 2 ; }
2015-04-02 20:32:22 +00:00
size *= 2 ;
break ;
case 'utf8' : o = _ _utf8 ( this , this . l , this . l + size ) ; break ;
case 'utf16le' : size *= 2 ; o = _ _utf16le ( this , this . l , this . l + size ) ; break ;
2017-02-22 06:57:59 +00:00
case 'wstr' :
2022-03-11 05:29:05 +00:00
if ( typeof $cptable !== 'undefined' ) o = $cptable . utils . decode ( current _codepage , this . slice ( this . l , this . l + 2 * size ) ) ;
2017-02-22 06:57:59 +00:00
else return ReadShift . call ( this , size , 'dbcs' ) ;
2017-03-10 08:39:51 +00:00
size = 2 * size ; break ;
2017-02-19 20:36:32 +00:00
2015-04-02 20:32:22 +00:00
/* [MS-OLEDS] 2.1.4 LengthPrefixedAnsiString */
2017-12-30 05:40:35 +00:00
case 'lpstr-ansi' : o = _ _lpstr ( this , this . l ) ; size = 4 + _ _readUInt32LE ( this , this . l ) ; break ;
case 'lpstr-cp' : o = _ _cpstr ( this , this . l ) ; size = 4 + _ _readUInt32LE ( this , this . l ) ; break ;
2015-04-02 20:32:22 +00:00
/* [MS-OLEDS] 2.1.5 LengthPrefixedUnicodeString */
2017-12-30 05:40:35 +00:00
case 'lpwstr' : o = _ _lpwstr ( this , this . l ) ; size = 4 + 2 * _ _readUInt32LE ( this , this . l ) ; break ;
2017-04-13 01:29:38 +00:00
/* [MS-OFFCRYPTO] 2.1.2 Length-Prefixed Padded Unicode String (UNICODE-LP-P4) */
case 'lpp4' : size = 4 + _ _readUInt32LE ( this , this . l ) ; o = _ _lpp4 ( this , this . l ) ; if ( size & 0x02 ) size += 2 ; break ;
/* [MS-OFFCRYPTO] 2.1.3 Length-Prefixed UTF-8 String (UTF-8-LP-P4) */
case '8lpp4' : size = 4 + _ _readUInt32LE ( this , this . l ) ; o = _ _8lpp4 ( this , this . l ) ; if ( size & 0x03 ) size += 4 - ( size & 0x03 ) ; break ;
2015-04-02 20:32:22 +00:00
case 'cstr' : size = 0 ; o = "" ;
while ( ( w = _ _readUInt8 ( this , this . l + size ++ ) ) !== 0 ) oo . push ( _getchar ( w ) ) ;
o = oo . join ( "" ) ; break ;
2017-03-28 22:03:03 +00:00
case '_wstr' : size = 0 ; o = "" ;
2015-04-02 20:32:22 +00:00
while ( ( w = _ _readUInt16LE ( this , this . l + size ) ) !== 0 ) { oo . push ( _getchar ( w ) ) ; size += 2 ; }
size += 2 ; o = oo . join ( "" ) ; break ;
/* sbcs and dbcs support continue records in the SST way TODO codepages */
case 'dbcs-cont' : o = "" ; loc = this . l ;
2018-02-08 18:21:39 +00:00
for ( i = 0 ; i < size ; ++ i ) {
2015-04-02 20:32:22 +00:00
if ( this . lens && this . lens . indexOf ( loc ) !== - 1 ) {
w = _ _readUInt8 ( this , loc ) ;
this . l = loc + 1 ;
vv = ReadShift . call ( this , size - i , w ? 'dbcs-cont' : 'sbcs-cont' ) ;
return oo . join ( "" ) + vv ;
}
oo . push ( _getchar ( _ _readUInt16LE ( this , loc ) ) ) ;
loc += 2 ;
} o = oo . join ( "" ) ; size *= 2 ; break ;
2017-12-04 04:41:41 +00:00
case 'cpstr' :
2022-03-11 05:29:05 +00:00
if ( typeof $cptable !== 'undefined' ) {
o = $cptable . utils . decode ( current _codepage , this . slice ( this . l , this . l + size ) ) ;
2017-12-04 04:41:41 +00:00
break ;
}
/* falls through */
2015-04-02 20:32:22 +00:00
case 'sbcs-cont' : o = "" ; loc = this . l ;
for ( i = 0 ; i != size ; ++ i ) {
if ( this . lens && this . lens . indexOf ( loc ) !== - 1 ) {
w = _ _readUInt8 ( this , loc ) ;
this . l = loc + 1 ;
vv = ReadShift . call ( this , size - i , w ? 'dbcs-cont' : 'sbcs-cont' ) ;
return oo . join ( "" ) + vv ;
}
oo . push ( _getchar ( _ _readUInt8 ( this , loc ) ) ) ;
loc += 1 ;
} o = oo . join ( "" ) ; break ;
default :
switch ( size ) {
case 1 : oI = _ _readUInt8 ( this , this . l ) ; this . l ++ ; return oI ;
case 2 : oI = ( t === 'i' ? _ _readInt16LE : _ _readUInt16LE ) ( this , this . l ) ; this . l += 2 ; return oI ;
2017-10-17 00:14:32 +00:00
case 4 : case - 4 :
2018-02-08 18:21:39 +00:00
if ( t === 'i' || ( ( this [ this . l + 3 ] & 0x80 ) === 0 ) ) { oI = ( ( size > 0 ) ? _ _readInt32LE : _ _readInt32BE ) ( this , this . l ) ; this . l += 4 ; return oI ; }
2017-03-12 18:02:43 +00:00
else { oR = _ _readUInt32LE ( this , this . l ) ; this . l += 4 ; } return oR ;
2017-10-17 00:14:32 +00:00
case 8 : case - 8 :
if ( t === 'f' ) {
if ( size == 8 ) oR = _ _double ( this , this . l ) ;
else oR = _ _double ( [ this [ this . l + 7 ] , this [ this . l + 6 ] , this [ this . l + 5 ] , this [ this . l + 4 ] , this [ this . l + 3 ] , this [ this . l + 2 ] , this [ this . l + 1 ] , this [ this . l + 0 ] ] , 0 ) ;
this . l += 8 ; return oR ;
} else size = 8 ;
2015-04-02 20:32:22 +00:00
/* falls through */
case 16 : o = _ _hexlify ( this , this . l , size ) ; break ;
} }
2014-01-28 16:38:02 +00:00
this . l += size ; return o ;
}
2017-09-30 06:18:11 +00:00
var _ _writeUInt32LE = function ( b /*:RawBytes|CFBlob*/ , val /*:number*/ , idx /*:number*/ ) /*:void*/ { b [ idx ] = ( val & 0xFF ) ; b [ idx + 1 ] = ( ( val >>> 8 ) & 0xFF ) ; b [ idx + 2 ] = ( ( val >>> 16 ) & 0xFF ) ; b [ idx + 3 ] = ( ( val >>> 24 ) & 0xFF ) ; } ;
var _ _writeInt32LE = function ( b /*:RawBytes|CFBlob*/ , val /*:number*/ , idx /*:number*/ ) /*:void*/ { b [ idx ] = ( val & 0xFF ) ; b [ idx + 1 ] = ( ( val >> 8 ) & 0xFF ) ; b [ idx + 2 ] = ( ( val >> 16 ) & 0xFF ) ; b [ idx + 3 ] = ( ( val >> 24 ) & 0xFF ) ; } ;
var _ _writeUInt16LE = function ( b /*:RawBytes|CFBlob*/ , val /*:number*/ , idx /*:number*/ ) /*:void*/ { b [ idx ] = ( val & 0xFF ) ; b [ idx + 1 ] = ( ( val >>> 8 ) & 0xFF ) ; } ;
2017-02-10 19:23:01 +00:00
2017-09-30 06:18:11 +00:00
function WriteShift ( t /*:number*/ , val /*:string|number*/ , f /*:?string*/ ) /*:any*/ {
2017-03-12 18:02:43 +00:00
var size = 0 , i = 0 ;
2014-06-29 18:29:45 +00:00
if ( f === 'dbcs' ) {
2017-03-12 18:02:43 +00:00
/*:: if(typeof val !== 'string') throw new Error("unreachable"); */
2017-02-10 19:23:01 +00:00
for ( i = 0 ; i != val . length ; ++ i ) _ _writeUInt16LE ( this , val . charCodeAt ( i ) , this . l + 2 * i ) ;
2014-06-29 18:29:45 +00:00
size = 2 * val . length ;
2017-02-10 19:23:01 +00:00
} else if ( f === 'sbcs' ) {
2022-03-11 05:29:05 +00:00
if ( typeof $cptable !== 'undefined' && current _ansi == 874 ) {
2019-11-15 01:46:49 +00:00
/* TODO: use tables directly, don't encode */
/*:: if(typeof val !== "string") throw new Error("unreachable"); */
for ( i = 0 ; i != val . length ; ++ i ) {
2022-03-11 05:29:05 +00:00
var cppayload = $cptable . utils . encode ( current _ansi , val . charAt ( i ) ) ;
2019-11-15 01:46:49 +00:00
this [ this . l + i ] = cppayload [ 0 ] ;
}
} else {
/*:: if(typeof val !== 'string') throw new Error("unreachable"); */
val = val . replace ( /[^\x00-\x7F]/g , "_" ) ;
/*:: if(typeof val !== 'string') throw new Error("unreachable"); */
for ( i = 0 ; i != val . length ; ++ i ) this [ this . l + i ] = ( val . charCodeAt ( i ) & 0xFF ) ;
}
2017-02-10 19:23:01 +00:00
size = val . length ;
2017-09-22 22:18:51 +00:00
} else if ( f === 'hex' ) {
for ( ; i < t ; ++ i ) {
/*:: if(typeof val !== "string") throw new Error("unreachable"); */
2018-02-08 18:21:39 +00:00
this [ this . l ++ ] = ( parseInt ( val . slice ( 2 * i , 2 * i + 2 ) , 16 ) || 0 ) ;
2017-09-22 22:18:51 +00:00
} return this ;
} else if ( f === 'utf16le' ) {
2017-09-30 06:18:11 +00:00
/*:: if(typeof val !== "string") throw new Error("unreachable"); */
2018-02-14 20:06:35 +00:00
var end /*:number*/ = Math . min ( this . l + t , this . length ) ;
2017-09-22 22:18:51 +00:00
for ( i = 0 ; i < Math . min ( val . length , t ) ; ++ i ) {
var cc = val . charCodeAt ( i ) ;
2018-02-08 18:21:39 +00:00
this [ this . l ++ ] = ( cc & 0xff ) ;
this [ this . l ++ ] = ( cc >> 8 ) ;
2017-09-22 22:18:51 +00:00
}
while ( this . l < end ) this [ this . l ++ ] = 0 ;
return this ;
2017-03-12 18:02:43 +00:00
} else /*:: if(typeof val === 'number') */ switch ( t ) {
2017-02-10 19:23:01 +00:00
case 1 : size = 1 ; this [ this . l ] = val & 0xFF ; break ;
case 2 : size = 2 ; this [ this . l ] = val & 0xFF ; val >>>= 8 ; this [ this . l + 1 ] = val & 0xFF ; break ;
case 3 : size = 3 ; this [ this . l ] = val & 0xFF ; val >>>= 8 ; this [ this . l + 1 ] = val & 0xFF ; val >>>= 8 ; this [ this . l + 2 ] = val & 0xFF ; break ;
case 4 : size = 4 ; _ _writeUInt32LE ( this , val , this . l ) ; break ;
case 8 : size = 8 ; if ( f === 'f' ) { write _double _le ( this , val , this . l ) ; break ; }
2014-05-29 22:30:03 +00:00
/* falls through */
case 16 : break ;
2017-02-10 19:23:01 +00:00
case - 4 : size = 4 ; _ _writeInt32LE ( this , val , this . l ) ; break ;
2014-05-29 22:30:03 +00:00
}
this . l += size ; return this ;
}
2017-09-30 06:18:11 +00:00
function CheckField ( hexstr /*:string*/ , fld /*:string*/ ) /*:void*/ {
2015-04-02 20:32:22 +00:00
var m = _ _hexlify ( this , this . l , hexstr . length >> 1 ) ;
2017-09-30 06:18:11 +00:00
if ( m !== hexstr ) throw new Error ( fld + 'Expected ' + hexstr + ' saw ' + m ) ;
2015-04-02 20:32:22 +00:00
this . l += hexstr . length >> 1 ;
}
2017-09-30 06:18:11 +00:00
function prep _blob ( blob , pos /*:number*/ ) /*:void*/ {
2014-07-28 13:22:32 +00:00
blob . l = pos ;
2017-09-30 06:18:11 +00:00
blob . read _shift = /*::(*/ ReadShift /*:: :any)*/ ;
2015-04-02 20:32:22 +00:00
blob . chk = CheckField ;
2014-06-29 18:29:45 +00:00
blob . write _shift = WriteShift ;
2014-01-28 16:38:02 +00:00
}
2017-09-30 06:18:11 +00:00
function parsenoop ( blob , length /*:: :number, opts?:any */ ) { blob . l += length ; }
2014-05-29 22:30:03 +00:00
2017-03-12 18:02:43 +00:00
function new _buf ( sz /*:number*/ ) /*:Block*/ {
2015-04-02 20:32:22 +00:00
var o = new _raw _buf ( sz ) ;
2014-06-29 18:29:45 +00:00
prep _blob ( o , 0 ) ;
2014-05-29 22:30:03 +00:00
return o ;
2014-06-29 18:29:45 +00:00
}
2014-05-29 22:30:03 +00:00