I am a newbie with julia and I am struggling a bit to understand FileIO.
I am trying to parse a file. I’d like to see a minimal working example. For example a module where I read text file (e.g. a .unv file and parse it line by line).
For instance, if we had a module call Uff.jl
:
module Uff
using FileIO
# Should the format be registered here or when using the module
add_format(format"UFF", (), [".uff",".unv"])
# Streaming based reader
function load(s::Stream{format"UFF"}; keywords...)
# s is already positioned after the magic bytes
# Do the stuff to read a PNG file
readline(s)
end
struct UFFReader
io::IO
ownstream::Bool
end
function Base.read(reader::UFFReader ) #, frames::Int)
# read and decode audio samples from reader.io
print(reader)
end
function Base.close(reader::UFFReader)
# do whatever cleanup the reader needs
reader.ownstream && close(reader.io)
end
loadstreaming(f::File{format"UFF"}) = UFFReader(open(f), true)
loadstreaming(s::Stream{format"UFF"}) = UFFReader(s, false)
# Reader based on the streaming
function load(q::Formatted{format"Uff"}, args...; kwargs...)
loadstreaming(q, args...; kwargs...) do stream
read(stream)
end
end
end
So it can be used as suggested in the documentation:
using FileIO
add_format(format"UFF", (), [".uff",".unv"], [:Uff])
test = loadstreaming("example.unv")
try
while !eof(audio)
line = read(test)
end
finally
close(test)
end