Images has (I think) basically already solved this problem. The way it uses magic numbers is described at https://github.com/timholy/Images.jl/blob/master/doc/extendingIO.md
For the example (a SIF) file, the magic bytes are enclosed in that b"Andor Technology Multi-Channel File" string. --Tim On Wednesday, April 08, 2015 05:58:11 AM Simon Danisch wrote: > This is half true. > Magic numbers are only used in ImageMagick.jl per "accident", as that's how > the underlying C-library does things. > To be honest, I haven't looked at the details yet myself, as I mostly copy > and pasted code to get a first prototype running. > I sketch out in FileIO.jl#3 <https://github.com/JuliaIO/FileIO.jl/issues/3#> > how I plan on using magic numbers. > If I find some time, I will make a schematic of some more advanced features > to handle ambiguities and different endings which map to the same type. > This should also give a better overview of the architecture and what a > package creator must do to get integrated into FileIO. > > Best, > Simon > > Am Samstag, 4. April 2015 17:41:14 UTC+2 schrieb Simon Danisch: > > Hi there, > > > > FileIO has the aim to make it very easy to read any arbitrary file. > > I hastily copied together a proof of concept by taking code from > > Images.jl. > > > > JuliaIO is the umbrella group, which takes IO packages with no home. If > > someone wrote an IO package, but doesn't have time to implement the FileIO > > interface, giving it to JuliaIO might be a good idea in order to keep the > > package usable. > > > > Concept of FileIO is described in the readme: > > > > Meta package for FileIO. Purpose is to open a file and return the > > respective Julia object, without doing any research on how to open the > > file. > > > > f = file"test.jpg" # -> File{:jpg}read(f) # -> Imageread(file"test.obj") # > > -> Meshread(file"test.csv") # -> DataFrame > > > > So far only Images are supported and MeshIO is on the horizon. > > > > It is structured the following way: There are three levels of abstraction, > > first FileIO, defining the file_str macro etc, then a meta package for a > > certain class of file, e.g. Images or Meshes. This meta package defines > > the > > Julia datatype (e.g. Mesh, Image) and organizes the importer libraries. > > This is also a good place to define IO library independant tests for > > different file formats. Then on the last level, there are the low-level > > importer libraries, which do the actual IO. They're included via Mike > > Innes > > Requires <https://github.com/one-more-minute/Requires.jl> package, so > > that it doesn't introduce extra load time if not needed. This way, using > > FileIO without reading/writing anything should have short load times. > > > > As an implementation example please look at FileIO -> ImageIO -> > > ImageMagick. This should already work as a proof of concept. Try: > > > > using FileIO # should be very fast, thanks to Mike Innes Requires > > packageread(file"test.jpg") # takes a little longer as it needs to load > > the IO libraryread(file"test.jpg") # should be fastread(File("documents", > > "images", "myimage.jpg") # automatic joinpath via File constructor > > > > Please open issues if things are not clear or if you find flaws in the > > concept/implementation. > > > > If you're interested in working on this infrastructure I'll be pleased to > > add you to the group JuliaIO. > > > > > > Best, > > > > Simon