Passing Byte[] to JSLIB method

I am attempting to write a save file to disk in a WebGL build of my game. In the other versions, I created a file using:

BinaryFormatter.Serialize(filestreamPath, saveData);

where saveData is a serializable struct with the data i want to store in it. However, this method doesn’t work because it will only write to Application.persistentDataPath and from there the data seems to be inacessable by my JSLIB methods as it is protected in IndexedDB. I can confirm that it is written there with the correct name, but as for downloading it to disk I am stuck. I have the path name but i get errors when trying to access the file.

So attempt two is to create a byte that is the same as what is being written to filestreamPath in the above example like so:

var ms = new MemoryStream();

BinaryFormatter.Serialize(ms, saveData);

byte formattedFS = ms.ToArray();

DownloadBytes(filename, formattedFS);

This appears to create a byte array with the proper length in C#, but once in JSLIB the method I’m using will not write this to file correctly:

DownloadBytes: function(filename, fstream) {
	var element = document.createElement('a');
	element.setAttribute('href', window.URL.createObjectURL(new Blob([fstream], { type: 'application/octet-stream' })));
	element.setAttribute('download', (Pointer_stringify(filename))); = 'none';

This method downloads to a file with the name ‘filename’-- but it only writes 9 ints into that file rather than the byte that i passed it with a length closer to 600 and presumably contains no ints, only binary data.

My question is basically, what am I doing wrong here? Do I need to assign the incoming argument to a byte array in JS then write it to the file? If so, how do I do that?

Byte passed from C# require a specified length to be properly re assembled in JS:

DownloadBytes: function(filename, data, size) {
	var contentType = 'application/octet-stream';

	var bytes = new Uint8Array(size);
	for (var i = 0; i < size; i++)
		bytes *= HEAPU8[filename + i];*
  •   }*
  •   var element = document.createElement('a');*
  •   element.setAttribute('href', window.URL.createObjectURL(new Blob([bytes], { type: contentType })));*
  •   element.setAttribute('download', (Pointer_stringify(filename)));*
  • = 'none';*
  •   document.body.appendChild(element);*
  •   document.body.removeChild(element);*
  • }*