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.
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...
KOS/src/kOS.Safe/Persistence/ArchiveFile.cs
Line 23 in 8f281a4
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:Stringfunction? 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:ReadAllmethod that looks at the file extension and skipsConvertFromWindowsNewlinesif 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.