license import { env } from '@tensorflow/tfjs-core' ; import { FileChunkIterator } from './file_chunk_iterator' ; const runes = `ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ
ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ
ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬` ; const testData = env ( ) . get ( 'IS_BROWSER' ) ? new Blob ( [ runes ] ) : Buffer . from ( runes ) ; describe ( 'ByteChunkIterator.decodeUTF8()' , ( ) => { it ( 'Correctly reassembles split characters' , async ( ) => { const byteChunkIterator = new FileChunkIterator ( testData , { chunkSize : 50 } ) ; expect ( ( env ( ) . get ( 'IS_BROWSER' ) ? ( testData as Blob ) . size : ( testData as Buffer ) . byteLength ) ) . toEqual ( 323 ) ; const utf8Iterator = byteChunkIterator . decodeUTF8 ( ) ; const result = await utf8Iterator . toArrayForTest ( ) ; expect ( result . length ) . toEqual ( 7 ) ; const totalCharacters = result . map ( x => x . length ) . reduce ( ( a , b ) => a + b ) ; expect ( totalCharacters ) . toEqual ( 109 ) ; expect ( result . join ( '' ) ) . toEqual ( runes ) ; } ) ; } ) ;