• Base64 to data (!Attacher, !StrongEd...)

    From Alexander Ausserstorfer@21:1/5 to All on Mon Jul 22 22:25:58 2024
    I've got a HTML-file which contains data in BASE64 like

    url("data:image/avif;base64,AAA...")

    I want to save and convert this BASE64 block to a data file. My idea is to
    use !Attacher to do the job.

    My problem is now that !Attacher seems to only do the job when the line is wrapped all 60 bytes like

    Content-Type: RISC OS; charset=US-ASCII; name=image.avif;fb2 Content-transfer-encoding: base64

    AAAAHGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZgAAAOptZXRhAAAAAAAAACFo ZGxyAAAAAAAAAABwaWN0AAAAAAAAAAAAAAAAAAAAAA5waXRtAAAAAAABAAAA Imlsb2MAAAAAREAAAQABAAAAAAEOAAEAAAAAAAXkhAAAACNpaW5mAAAAAAAB AAAAFWluZmUCAAAAAAEAAGF2MDEAAAAAamlwcnAAAABLaXBjbwAAABNjb2xy bmNseAACAAIABoAAAAAMYXYxQ4EsAgAAAAAUaXNwZQAAAAAAAAqiAAAHCAAA ABBwaXhpAAAAAAMICAgAAAAXaXBtYQAAAAAAAAABAAEEgYIDhAAF5IxtZGF0 EgAKBzsuqoeD8Egy9cgXEcABhjjBQPkMmn2bLw2MPTSkNWgveNPfS7Yfr0zT pvctZrPpKeCfv6r0KCA6qqZlTYwTgHyZTko6a4Dh+gNayZQs2mV8XUKe/jBN bC3sQ3D4/BV7p0pOuayUAodsk/6GRZP+kFJbXg7w7taFAgNEBQmo5tV8X/nK YO1y+PcnB2qqa7awaF8ypsLsnqHPMcfLZM87uSjgxbnjwxh1G3otoIDg0Rvu 8pQs+h4L4I4yhOJsUMZeZsS6bKVALn6WU12np+EJn+JRJ4gJAuBkYpENx9MZ

    But this isn't here the case. The belonging block in the HTML-file is
    endless. How can I insert all 60 bytes a new line? I tried the wrap
    options Hardwrap 60 in StrongEd, but this seems to do nothing.

    Any ideas please?

    Thanks in advance!

    A.

    --
    http://home.chiemgau-net.de/ausserstorfer/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harriet Bazley@21:1/5 to Alexander Ausserstorfer on Tue Jul 23 09:54:07 2024
    On 22 Jul 2024 as I do recall,
    Alexander Ausserstorfer wrote:

    I tried the wrap options Hardwrap 60 in StrongEd, but this seems to do nothing.


    The "Hardwrap" feature only works when you actively edit a paragraph in StrongED. It is designed for writing e-mail and similar tasks where you
    are creating text from scratch, rather than for converting wrapped text
    into text with hard line endings.

    You can use it to carry out the task you want by placing the cursor in
    the block and using the Ctrl-R keyboard shortcut to forcibly 'rewrap'
    that section.

    An easier and more memorable way of doing it without altering the mode
    settings is probably to toggle automatic wrapwidth by clicking on the
    width indicator at the bottom of the window (by default this reads '80';
    if you clock on this figure it will change to 'a80') and resize the
    window and hence the text to whatever width you want, in the case until
    the indicator reads 'a60'. Then select the relevant section with the
    mouse and select "Unwrap (split) lines" from the bottom entry in the
    menu (if you are in the default BaseMode the menu entry will read BaseMode->Unwrap).

    --
    Harriet Bazley == Loyaulte me lie ==

    He who hesitates is sometimes saved.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jean-Michel@21:1/5 to Alexander Ausserstorfer on Tue Jul 23 10:27:42 2024
    In message <[email protected]>
    Alexander Ausserstorfer <[email protected]> wrote:

    I've got a HTML-file which contains data in BASE64 like

    url("data:image/avif;base64,AAA...")

    I want to save and convert this BASE64 block to a data file. My idea is to use !Attacher to do the job.

    My problem is now that !Attacher seems to only do the job when the line is wrapped all 60 bytes like

    Content-Type: RISC OS; charset=US-ASCII; name=image.avif;fb2 Content-transfer-encoding: base64

    AAAAHGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZgAAAOptZXRhAAAAAAAAACFo ZGxyAAAAAAAAAABwaWN0AAAAAAAAAAAAAAAAAAAAAA5waXRtAAAAAAABAAAA Imlsb2MAAAAAREAAAQABAAAAAAEOAAEAAAAAAAXkhAAAACNpaW5mAAAAAAAB AAAAFWluZmUCAAAAAAEAAGF2MDEAAAAAamlwcnAAAABLaXBjbwAAABNjb2xy bmNseAACAAIABoAAAAAMYXYxQ4EsAgAAAAAUaXNwZQAAAAAAAAqiAAAHCAAA ABBwaXhpAAAAAAMICAgAAAAXaXBtYQAAAAAAAAABAAEEgYIDhAAF5IxtZGF0 EgAKBzsuqoeD8Egy9cgXEcABhjjBQPkMmn2bLw2MPTSkNWgveNPfS7Yfr0zT pvctZrPpKeCfv6r0KCA6qqZlTYwTgHyZTko6a4Dh+gNayZQs2mV8XUKe/jBN bC3sQ3D4/BV7p0pOuayUAodsk/6GRZP+kFJbXg7w7taFAgNEBQmo5tV8X/nK YO1y+PcnB2qqa7awaF8ypsLsnqHPMcfLZM87uSjgxbnjwxh1G3otoIDg0Rvu 8pQs+h4L4I4yhOJsUMZeZsS6bKVALn6WU12np+EJn+JRJ4gJAuBkYpENx9MZ

    But this isn't here the case. The belonging block in the HTML-file is endless. How can I insert all 60 bytes a new line? I tried the wrap
    options Hardwrap 60 in StrongEd, but this seems to do nothing.

    Any ideas please?

    Thanks in advance!

    A.

    You can use !StrongED to align lines to 60 characters.
    Once the file is loaded (text) select the block to split, choose wrapwith
    = 60, then with basemode menu unwrap(split) lines. Splitting is done.

    I don't know enough about !Attacher to know what type of file to provide.
    Yours seems to be AVI, it's also the type that !Attacher provides.
    This decoding interests me because it is a possibility that I would like
    to add to my SVG file decoding.

    Feedback for your decoding is welcome.

    --
    Jean-Michel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Alexander Ausserstorfer@21:1/5 to Jean-Michel on Tue Jul 23 18:50:10 2024
    In article <[email protected]>,
    Jean-Michel <[email protected]> wrote:

    You can use !StrongED to align lines to 60 characters. Once the file
    is loaded (text) select the block to split, choose wrapwith = 60, then
    with basemode menu unwrap(split) lines. Splitting is done.

    Merci beaucoup. That worked here (after a time). I'm just wonder what
    I'm doing now with the binary file. I thought it is an image but it
    seems that no application of RISC OS here can load or convert it to
    another (usefull) format.

    A.

    --
    http://home.chiemgau-net.de/ausserstorfer/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From druck@21:1/5 to Alexander Ausserstorfer on Tue Jul 23 21:07:38 2024
    On 22/07/2024 21:25, Alexander Ausserstorfer wrote:
    I want to save and convert this BASE64 block to a data file. My idea is to use !Attacher to do the job.

    Python has a base64 module and you can pass any length string to it's
    decode function. I haven't checked if it's available on RISC OS though.

    ---druck

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jean-Michel@21:1/5 to druck on Wed Jul 24 10:24:00 2024
    In message <v7p2ia$1bf9s$[email protected]>
    druck <[email protected]> wrote:

    On 22/07/2024 21:25, Alexander Ausserstorfer wrote:
    I want to save and convert this BASE64 block to a data file. My idea is to >> use !Attacher to do the job.

    Python has a base64 module and you can pass any length string to it's
    decode function. I haven't checked if it's available on RISC OS though.

    ---druck
    Yes,
    To test Python code (works with Python3 on RISC OS)

    import base64, binascii
    # to replace with your string.
    base64_string = "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tI FVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvI
    E1peGVyIFRvb2xzIC0tPgo8c3ZnIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iM
    CAwIDUxMiA1MTIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZmlsbD0iI
    zAwMDAwMCIgZD0iTTQ1OC45MTUgMzA3LjcwNWMwIDYyLjYzLTU0IDkxLjMyLTkxLjM0IDkxLjM0LTQxL
    jY0IDAtNzMuMS0xOC44Ni05MS44My0zNC4yNiAyLjQ3IDUwLjk1IDE0LjUzIDg3LjM1IDY4LjY1IDExN
    mgtMTc2Ljc5YzU0LjEyLTI4LjY1IDY2LjE4LTY1LjA1IDY4LjY1LTExNi0xOC43MyAxNS4zOS01MC4yI
    DM0LjI4LTkxLjgzIDM0LjI2LTM3LjI5IDAtOTEuMzQtMjguNzEtOTEuMzQtOTEuMzQgMC0xMTQuNDcgO
    DAuNjQtODMuMzIgMjAyLjkxLTI3Ni40OSAxMjIuMjggMTkzLjE3IDIwMi45MiAxNjIuMDMgMjAyLjkyI
    DI3Ni40OXoiLz48L3N2Zz4="

    try:
    image = base64.b64decode(base64_string, validate=True)
    file_to_save = "my_image/png"
    with open(file_to_save, "wb") as f:
    f.write(image)
    except binascii.Error as e:
    print(e)


    the code produces a tex type file, in fact it is an SVG file, change the
    type and drop it on the !Netsurf icon, you got a "spade"
    I tried with other "strings" and I got PNG which had been Base64 encoded.

    To test with your string, no split needing.


    --
    Jean-Michel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)