• Saving binary from base64 with File class

    From Nightfox@VERT/DIGDIST to All on Saturday, September 19, 2015 20:31:30
    Hi all,

    I was looking at the Synchronet JavaScript API documentation for the File class:
    http://www.synchro.net/docs/jsobjs.html#File
    It says the File class has support for binary files and automatic Base64 decoding (among other features). It sounds to me like if I have some Base64-encoded data, I should be able to write that to a file using the File class and it will automatically decode it to binary format. I've tried opening a file with the mode "wb" (write binary) and using the write() method to write the Base64-encoded data. It's not decoding the data to binary though - it's just writing the Base64 string to the file. Might I be missing a step to get it to convert Base64 data to binary?

    Basically my flow is this:

    var B64Data = "some Base64-encoded data";
    var destFile = new File("someFile.bin");
    if (destFile.open("wb"))
    {
    destFile.write(B64Data);
    destFile.close();
    }

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Saturday, September 19, 2015 23:48:42
    Re: Saving binary from base64 with File class
    By: Nightfox to All on Sat Sep 19 2015 08:31 pm

    Hi all,

    I was looking at the Synchronet JavaScript API documentation for the File class:
    http://www.synchro.net/docs/jsobjs.html#File
    It says the File class has support for binary files and automatic Base64 decoding (among other features). It sounds to me like if I have some Base64-encoded data, I should be able to write that to a file using the File class and it will automatically decode it to binary format. I've tried opening a file with the mode "wb" (write binary) and using the write() method to write the Base64-encoded data. It's not decoding the data to binary though - it's just writing the Base64 string to the file. Might I be missing a step to get it to convert Base64 data to binary?

    Basically my flow is this:

    var B64Data = "some Base64-encoded data";
    var destFile = new File("someFile.bin");
    if (destFile.open("wb"))
    {
    destFile.write(B64Data);
    destFile.close();
    }

    Set destFile.base64=true, other than that, looks right.

    digital man

    Synchronet "Real Fact" #84:
    The ZMODEM file transfer protocol is limited to files of 4 gigabytes or smaller.
    Norco, CA WX: 75.9øF, 62.0% humidity, 0 mph SSE wind, 0.00 inches rain/24hrs

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ telnet://vert.synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Sunday, September 20, 2015 08:45:37
    Re: Saving binary from base64 with File class
    By: Digital Man to Nightfox on Sat Sep 19 2015 23:48:42

    Set destFile.base64=true, other than that, looks right.

    Ah, I hadn't noticed that in the docs. Thanks.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com