Read ASCII file in Pluto (convert a Vector{UInt} to a Vector{String} similar to readlines)

I am reading data into Pluto from an ASCII file. I note that when I use the PlutoUI command

@bind name PlutoUI.FilePicker([MIME("text/plain")])

that it returns both the file name and the data in some format. What I want is the data from the file. Let’s say we have a file such as

open("my_file.txt", "w") do io
    write(io, "JuliaLang is a GitHub organization.\nIt has many members.\n");
end

we can then read the data using

readlines(name["name"])

which displays in Pluto as

["JuliaLang is a GitHub organization.", "It has many members."]

However this only works in the current working directory, as the file path is not tracked. Since there is also a variable name["data"], I am wondering if I can create a Vector of Strings equivalent to the readlines command from this information?

More information

typeof(name["data"])

yields

Vector{UInt8} (alias for Array{UInt8, 1})

and

convert.(Char, name["data"])

gives


'['
'W'
'i'
'n'
more
'\t'
'0'
'\r'
'\n'
'\r'
'\n'

I think I can create a function to make this into a vector of Strings like readlines() does, but I also suspect there is a command within Julia that will do this. Will keep looking and appreciate your help.

More playing around I got it! Eureka!

filelines = readlines(IOBuffer(name["data"]))

You could also use split(name["data"], '\n')

Hmm, tried it and split does not like a Vector{Uint8}. If I modify it to

split(string(Char.(name["data"])...), '\n')

to convert it to a Vector{Char} and from there to a string, then the split does work.

You can directly do String(name["data"]) which is more efficient because it directly utilizes the memory and doesn’t need to construct intermediates. It also empties the original vector though.