# FileIO - Minimal example

**URL:** <https://discourse.julialang.org/t/fileio-minimal-example/18097>\
**Category:** New to Julia\
**Created:** [November 28, 2018, 12:38pm UTC](https://discourse.julialang.org/t/fileio-minimal-example/18097 "2018-11-28T12:38:52Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![josemaria](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josemaria/32/5365_2.png) [@josemaria](https://discourse.julialang.org/u/josemaria)\
**Post date:** [November 28, 2018, 2:38pm UTC](https://discourse.julialang.org/t/fileio-minimal-example/18097/2 "2018-11-28T14:38:48Z")

</div>

The following seems to work.

I have created a module `Uff.jl`:

```julia
module Uff

using FileIO

struct UFFReader
    io::IO
    ownstream::Bool
end

function Base.read( reader::UFFReader )
    # read and decode audio samples from reader.io
    readline(reader.io)
end

function Base.close(reader::UFFReader)
    # do whatever cleanup the reader needs
    reader.ownstream && close(reader.io)
end

Base.eof(reader::UFFReader) = eof( reader.io )

loadstreaming(f::File{format"UFF"}) = UFFReader(open(f.filename), true)
loadstreaming(s::Stream{format"UFF"}) = UFFReader(s, false)

end

```

Just for the record it seems to work when I do:

```julia
using FileIO
using Uff

add_format(format"UFF", (), [".uff",".unv"], [:Uff])

loadstreaming("example.unv") do io
   while !eof(io)
     print(read(io))
   end
end

```

So it is a matter of replacing `readline(reader.io)` for whatever parser needs to be used and replacing `print(read(io))` for whatever processing we want to do in the future.

I will keep posting improvements as I learn them. (Just for the record)

---

_[View the full topic](https://discourse.julialang.org/t/fileio-minimal-example/18097)._
