Factorio seems to output base64 strings with wrong padding

Bugs that are actually features.
Post Reply
CheeseMcBurger
Inserter
Inserter
Posts: 48
Joined: Sun May 19, 2019 9:57 pm
Contact:

Factorio seems to output base64 strings with wrong padding

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13240
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Factorio seems to output base64 strings with wrong padding

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2253
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Factorio seems to output base64 strings with wrong padding

Post 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

CheeseMcBurger
Inserter
Inserter
Posts: 48
Joined: Sun May 19, 2019 9:57 pm
Contact:

Re: Factorio seems to output base64 strings with wrong padding

Post by CheeseMcBurger »

Thanks boskid, I missed the leading zero! Base64's are now all valid!

Post Reply

Return to “Not a bug”