TextDecoder in three.module.js return empty string

There is an .stl file with charset us-ascii which must decode as string. It size is 622MB which used LoaderUtils in three.module.js to decode ascii ArrayBuffer But gotten empty string "".
For lighter files it works correctly.

class LoaderUtils {

	static decodeText( array ) {

		if ( typeof TextDecoder !== 'undefined' ) {

            // array is ArrayBuffer - Uint8Array
            console.log( array.length ); // 621757404

			return new TextDecoder().decode( array );

		}

	}
}

How can it be solved ?

using of String.fromCharCode.apply(null, array) frieze browser 

The file is probably too big. Consider to break down the file into smaller pieces and parse it incrementally.

BTW: This is not a three.js specific issue. TextDecoder is part of the Web API, see:

1 Like

Thanks. I will try your solution. This problem occurs just in chrome.

There is a maximum for arguments length passed to function.

On my machine:

alert.apply(window, new Array(5E5)); // FireFox
alert.apply(window, new Array(125313)); // Chrome

If args are increased by one factor, it throws an error.

Solution: use loop.

I break down the file into smaller pieces and decode it separately but i got other error. What is your recommendation?

RangeError: Invalid string length at Array.join