Skip to content

ArchiveFile:ReadAll Mangles files by encoding and decoding to utf8 when undesired #3187

@BAM5

Description

@BAM5

I thought I was being clever, making 128 different files with a single byte value in it to give me the ability to write a byte of any value to a file...
My god what a headache. I spent hours into the night figuring out what the issue was. It was this one line of code...

bytes = Archive.ConvertFromWindowsNewlines(bytes);

You see, this function decodes and encodes any data, binary or not, if it doesn't pass some coarse check to see if it ISN'T a string. In my case, this function will categorize the file as "TOO SHORT" and this function throws up its hands and says "Screw it! It's a string!" This has ruined me royally.

I request a bit better logic here. This whole issue is revolving around this function that swaps windows linebreak sequence with the typical singular newline character. So the simplest thing to do is leave practically all the logic as is, and then at the end, just do a length check of the original decoded string and the string after replacement. If it's shorter, I suppose we can assume that it was a string and encode and return it. If not, just return the original bytes.

I guess this won't work for binary files with strings embedded though so...
Maybe we move the function to the FileContent:String function? Then it will only execute when the consumer wants the data as a string. When they request the Binary, they'll get the original data.

Or maybe just have a check in the ArchiveFile:ReadAll method that looks at the file extension and skips ConvertFromWindowsNewlines if it's ".bin" or something. At least this way there's a clear flag from user-space that gives us the intention of the file.

It's 3:20. I'm going to sleep. Upset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions