Hi Simon,
Thanks for the comments.
>In the end, I would rather like to have the hierarchy in the Julia objects
that get returned by load (e.g. AbstractString <: UTF8String etc)
Hmm... Did not think of this... I guess because an encoding is not
technically a string, but maybe that does not matter...
>- There are many IO libraries which should get dynamically loaded when the
format is detected (first argument for registry)
I don't think I really understand this part... I usually like to explicitly
pick which libraries I want my program to use... But it looks like FileIO
auto-loads libraries. I'm not saying this is necessarily a bad thing...
I'm just not used to thinking that way.
>- we utilize magic bytes to recognize file formats (second argument for
registry)
Indeed that part is great! I just don't need it at the moment - because
with the code I am writing (right know) I already know the file type.
That said: I *know* I can make use of the magic byte detection in the
future. Thanks for that!
>- there are multiple IO libraries for the same formats and we need to
choose one dynamically.
Maybe that's one of the things I don't get fully... I would expect that if
you have two PNG reader libraries:
using MyPNGLib
or
using ThisGuysEvenBetterPNGLib
Then, whichever library was "using"d should have registered itself with
FileIO, and would then be used when the user calls:
img = load(File{format"PNG"}("thisimage.png"))
>>but something seems a little off about how I use/generate objects
>I'm not really sure what you mean by that.
Indeed... I'm not sure either... I'm trying to figure that out:
At the moment, one thing I can think of are issues I expect when building
an image editor program:
module MyImageEditor #Think of something like GIMP
#This would be a high-level open function that does everything necessary to
#"open" the file to a new canvas:
function open{T<:PixelImageFormat}(file::File{T})
data = FileIO.load(file)
#Create new canvas
#Populate canvas with data
#Show canvas
end
function open{T<:VectorImageFormat}(file::File{T})
#Ask user what resolution they want for the rendered bitmap
data = FileIO.load(file)
#Create new canvas
#Render vector image to canvas
#Populate canvas with data
#Show canvas
end
#For any other file:
function open{T}(file::File{T})
throw("Cannot open this kind of file... not a (recognized) image")
end
#When the user clicks "ok":
function imgopendlg_ok(dlg::ImgOpenDlg)
#I assume FileIO could have an "autodetect" function that tries to
#determine the most likely file type from the extension, then confirm
#everything is ok using magic byes....
file = FileIO.autodetect(dlg.filepath)
#Now file is a File object with type information.
try
open(file)
catch e
display_message(e)
end
end
end #module
As far as I can tell: If I were to try to open a large movie instead of a
pixel image, I expect the following issues:
1) The current implementation of FileIO will try to auto-load the movie
libraries I don't want to include with my program (because the code to
register file readers is actually *inside* the FileIO module?? - I think?)
2) I would have to wait until my program has loaded the movie file before I
can detect it was a movie file, and *then* I can finally catch it as an
exception:
function open(file::File) #In MyImageEditor
data = FileIO.load(file)
if !isimage(data)
throw("Cannot open this kind of file... not a (recognized) image")
end
#Create new canvas
#Populate canvas with data
#Show canvas
end
isimage(data::PNGData) = true
isimage(data::BMPData) = true
...
isimage(unknowndata) = false
...Or something similar.
To be fair: I am almost certain the the biggest reason for my unease with
FileIO is that I have not seen enough examples on how to use the module
properly.
Can you point me to good example projects/other modules that use FileIO as
intended? I am only getting a vague feel for its use by reading the
included tests.
Otherwise: I guess I will wait until more examples are available - or keep
trying to play around with FileIO's capabilities when I have time.
Best Regards,
MA