Alternative to base64 encoding?

In my game(which is multiplayer, in a style similar to FPS'), I'm making a system which the server uploads the map to the client upon connection. The server-client system is made using websockets, and I've managed to build said uploading system already, but theres this one problem: the map file is converted to base64 before being sent, and base64 increases filesize by up to 50%, thus the upload is much slower(And I need to convert the file to some type of string before sending, because working with streams, buffers,etc in this case would be much harder and/or require me changing the module I'm using for the server, thus changing the whole structure).

Is there any alternative to base64 encoding in nodejs, that works for my case? Or any way to reduce string size of something converted to base64?
Convert the string to a bytearray. Or, if you want to be more precise, Uint8Array.
Try using a compression algorithm on the string before sending, then decompress after receiving.
Convert the string to a bytearray. Or, if you want to be more precise, Uint8Array.
I tried to find ways to convert it to Uint8Array and back, but none I found worked the way I wanted(some even have broken the server)

Try using a compression algorithm on the string before sending, then decompress after receiving.
Well, the server will be required to zip all files into a single .zip file, so its somewhat compressed already. I'll try to find ways to reduce string size before sending(although I need methods that allow to get the original string back in place when its sent to the client).


I also made some research on how Buffer().toString() works, and what types of encondig it accepts, and found I could use the following:
ascii, utf8, utf16le, ucs2 (alias of utf16le), base64, binary and hex

I'm now using binary encoding, as the string will take as much filesize as the original file, thus being far better than base64. Anyone with better knowledge than me knows if the other alternatives are better when it comes to size?
Wouldn't be a bad idea to know how they are supposed to work and how they work 😀 I have used both ByteArrays and Uint8Arrays quite successfully in conbination with text strings.

Code:
let ua = new Uint8Array(str.length);
for (let i in str) ua[i] = str.charCodeAt(i);
In fact maybe a classic int array could be even smaller, although I'm not entirely sure about that right now.

Edit: Binary encoding is the smallest possible one. Utf encoding uses 2-4 bytes per character, while classic string uses 1 byte per character. Ascii vs. Unicode is irrelevant if we're speaking about standard alphabet, so keeping it at binary might be your best bet.
Code:
let ua = new Uint8Array(str.length);
for (let i in str) ua[i] = str.charCodeAt(i);

Most string to int array and back methods(this one included) seems to... not be as optimal as necessary. This one, like some others I tested, for example simply crashed the server when converting a file of around 34MB(which is not that big for a custom map). Builtin methods I found had size limitations(of around 100k characters)...
In that case the only way I can recommend is compression of a binary string as there is no smaller size of a string than of a binary string. LZString has a couple of compression functions and it's a native module to MV, so you may use that.

Btw. I can confirm that conversion between an Uint8Array and String is quite a memory hog, which is why your server crashed. I could convert 10 MB of a file. But 50 MB led to the game crashing on my 4 GB RAM tablet.

Original thread: https://forums.rpgmakerweb.com/threads/alternative-to-base64-encoding.107467/