import { serialize , deserialize } from 'bson' ; import zlib from 'zlib' ; export default class Z64Serialize { static serializeSync ( obj ) { return zlib . deflateSync ( serialize ( obj ) ) ; } static deserializeSync ( buf ) { return deserialize ( zlib . inflateSync ( buf ) , { promoteBuffers : true , promoteValues : true } ) ; } static deserialize ( buf ) { return new Promise ( ( accept , reject ) => { zlib . inflate ( buf , ( error , result ) => { if ( error ) { reject ( "Failed to deserialize data." ) ; return ; } accept ( deserialize ( result , { promoteBuffers : true , promoteValues : true } ) ) ; } ) ; } ) ; } static serialize ( obj ) { return new Promise ( ( accept , reject ) => { zlib . deflate ( serialize ( obj ) , ( error , result ) => { if ( error ) { reject ( "Failed to serialize data" ) ; return ; } accept ( result ) ; } ) ; } ) ; } static FixArray ( fakeArray ) { let arr = [ ] ; Object . keys ( fakeArray ) . forEach ( ( key ) => { arr . push ( fakeArray [ key ] ) ; } ) ; return arr ; } }