Page 1 of 1

Txt file loading problem

PostPosted: Sat Mar 28, 2020 4:58 pm
by tektoog
Hey,
Can someone enlight me on this?
I just can't open this text file with the text load primitive.
I guess it has something to do with raw and rich text formatting, ASCII or something like that…
What I'm trying to do is to get the available free space for a disk…
The 2 files are generated by 2 different expressions thru PowerShell and lead, obviously to 2 different kind of formatting…
I know that this has already been done with ruby, but it's just that I don't like to not know...
Please, can someone confirm this? (just open the text files with the txt load primitive)
Any help would be greatly appreciated ;)

logfile.rar
Works
(182 Bytes) Downloaded 719 times

logfile.rar
Do NOT work
(133 Bytes) Downloaded 724 times

Re: Txt file loading problem

PostPosted: Sat Mar 28, 2020 5:10 pm
by tulamide
Flowstone does not support multi-byte encoding. The not working one is encoded with UTF 16 (= 2 bytes per char). You got away with the first one, as it uses 1 byte per char although still UTF encoded. This can give you issues outside of the standard ASCII range (7 bit), because there the indices don't match anymore.

If you want to be 100% sure, save your text ANSI-encoded (= full ASCII, 8 bit).

Re: Txt file loading problem

PostPosted: Sat Mar 28, 2020 5:35 pm
by tektoog
Thx Tulamide for your explanations. ;)
So would you know what kind of argument I should add to the expression to format the redirected file as a correct ANSI format?
Also when I get the result in a string component and then pass it thru an integer prim… :cry:
I kind of feel dumb to ask that, but how can I get the right number? It seems I've never encountered this issue before... :?
TxtLoadProb.fsm
(2.55 KiB) Downloaded 743 times

Re: Txt file loading problem

PostPosted: Sat Mar 28, 2020 6:13 pm
by wlangfor@uoguelph.ca
if your project is something commercial maybe check out the native ruby text load, it has the option of loading practically any encoding.

If you were making a plugin designed to load text files, it'd make a lot of sense.

Re: Txt file loading problem

PostPosted: Sat Mar 28, 2020 6:14 pm
by tulamide
I never worked with PowerShell, but a quick google search got this:
Code: Select all
Set-Content -LiteralPath "$filePath" -Encoding Ascii


But I'm afraid you have to find out on your own, how this will help you!

Flowstone integers are signed 32 bit. That means the maximum positive value they can hold is 2,147,483,647. Of course, on a 64-bit file system you exceed the limit. Luckily, Ruby's integer are of "on demand" bit depth, so it is no issue for Ruby to work with that big numbers. Once you made the number smaller than above mentioned signed 32-bit limit, you can output it to green.

Quick'n'dirty direct conversion example in Ruby, where the only input is a string and the only output an integer:
Code: Select all
output(0, @in.to_i / 1024 / 1024 / 1024)
#outputs rounded Gigabytes

Re: Txt file loading problem

PostPosted: Sat Mar 28, 2020 6:48 pm
by trogluddite
wlangfor@uoguelph.ca wrote:check out the native ruby text load, it has the option of loading practically any encoding

In native Ruby, yes; but unfortunately, the Ruby interpreter embedded in FS only includes support for ASCII-8BIT, UTF-8, and US-ASCII (in v3.0.6 at least - type "Encoding.list" into a RubyEdit primitive to see the supported encodings).

Re: Txt file loading problem

PostPosted: Sat Mar 28, 2020 11:52 pm
by tektoog
Thanks for your answers, guys! :D
After a good meal and looking deeper into this, my conclusion is that it's not easy to get a conversion from one format to another with just a command line... a full script would be needed to get to the desired result, involving external batch processing blahblahblah…
trogluddite wrote:type "Encoding.list" into a RubyEdit primitive to see the supported encodings

Great, useful info! does it work with other keywords? good way to learn the possible commands with this method...
Well,looking forward to a possible TXTLoad primitive update then... :? ;)

Re: Txt file loading problem

PostPosted: Sun Mar 29, 2020 3:25 am
by trogluddite
tektoog wrote:Great, useful info! does it work with other keywords? good way to learn the possible commands with this method...

Ruby has a lot of methods which can be useful for discovering what features are available, either by typing them into an empty RubyEdit or by displaying them using the "watch" method from running code. You can find out what variables and constants are declared, what methods an object or Class has, the current environment variables, and a whole lot more. Generally, they're more useful for debugging than for learning from, but there are a few undocumented FS Ruby features which have been discovered by using them to poke around under the hood.

For example, calling ".instance_methods" on the name of a class will list all of the methods which object of that class can respond to (or you can just call ".methods" on any individual instance).

Re: Txt file loading problem

PostPosted: Sun Mar 29, 2020 3:43 am
by tektoog
Thanks a lot for your enlightment!
I definitely will need 2 lives... :D ;)