Page 1 of 1

Factorio seems to output base64 strings with wrong padding

Posted: Fri Aug 25, 2023 11:49 pm
by CheeseMcBurger
I noticed that I cannot decode many the Base64 string that come out of Factorio, when the base64 decoder does not ignore the padding. For example, this one.

https://base64.guru/tools/validator says it is invalid
https://onlinebase64tools.com/validate-base64 says it is invalid

Javascript fetch() is unable to decode the string

Code: Select all

const bpString = "0eNrNfV2PG8mR...y/8AuS2WkQ=="
const bpBinary = await fetch("data:application/octet-stream;base64," + bpString)
Python also struggles, if you enforce validation.

Code: Select all

bp_string = "0eNrNfV2PG8mR...y/8AuS2WkQ=="
base64.b64decode(s, validate=True)
I understand this is a very minor thing, but it would help if the base64 encoded string would have proper padding, because some libraries don't do well with it. JavaScripts atob() and fetch() does not work at all and you cannot disable strict mode.

Re: Factorio seems to output base64 strings with wrong padding

Posted: Sat Aug 26, 2023 12:00 am
by Rseding91
Thanks for the report however I don't see this ever changing. The strings are primarily intended to be used between instances of Factorio. It just happens that base64 made for a format that was plain text compatible to allow easy sharing between players. If external tools can or can't use that isn't really a concern. Because the padding is unnecessary and ends up discarded anyway any script or tool can simply add it themselves if they are using a language that can't deal with it not existing.

Re: Factorio seems to output base64 strings with wrong padding

Posted: Sat Aug 26, 2023 6:03 am
by boskid
First character, a "0" is not part of base64, its our format version indicator, thats what is throwing you off

https://wiki.factorio.com/Blueprint_string_format

Re: Factorio seems to output base64 strings with wrong padding

Posted: Sat Aug 26, 2023 9:14 pm
by CheeseMcBurger
Thanks boskid, I missed the leading zero! Base64's are now all valid!