# A tip for integrating your new format without changing \`FileIO\`'s registry

**URL:** <https://discourse.julialang.org/t/a-tip-for-integrating-your-new-format-without-changing-fileio-s-registry/111129>\
**Category:** Data\
**Tags:** io, tip\
**Created:** [March 4, 2024, 12:33pm UTC](https://discourse.julialang.org/t/a-tip-for-integrating-your-new-format-without-changing-fileio-s-registry/111129 "2024-03-04T12:33:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ehgus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ehgus/32/21727_2.png) [@ehgus](https://discourse.julialang.org/u/ehgus)\
**Post date:** [March 4, 2024, 12:33pm UTC](https://discourse.julialang.org/t/a-tip-for-integrating-your-new-format-without-changing-fileio-s-registry/111129/1 "2024-03-04T12:33:08Z")

</div>

I tried to **implement a new data format** for internal use and share **how I register a new data format** without altering FileIO’s registry. It’s obvious to someone, but I hope someone finds it helpful.

## List of solutions

To integrate your I/O packages to FileIO, you should register your custom file format to FileIO. There are following approaches:  
(1) Update `registry.jl` of FileIO.  
(2) Explicitly execute `add_format(...)` before the use.  
(3) Automatically call `add_format(...)` while importing the custom I/O package.

The first method is what is written in the FileIO’s documentation. For my case, I ignore this solution to prevent “custom FileIO” because my I/O package is for internal use and full request is not an option.

A few people facing the similar problem to me choose the second solution [[fileio minimal example](https://discourse.julialang.org/t/fileio-minimal-example/18097/2),[MeshIO.jl at experimental stage](https://discourse.julialang.org/t/how-to-load-urdf-files-with-dae-models-into-meshcat/19509/3)]. I made an example code (suppose I made a `_TestTemplates.jl` package):

```Julia
using _TestTemplates
using FileIO
detect_test(io) = endswith(io.name,".test>")
add_format(format"TEST",detect_test,[".test"], [:_TestTemplates])

save("test.test","Hello, world")
load("test.test") # return "Hello, world"

```

However, this should be done manually and tedious. I want to hide the registration lines inside package.

I suggest to use \_\_init\_\_ in the package :

```Julia
# In the middle of package
function __init__ ()
    detect_test(io) = endswith(io.name,".test>")
    add_format(format"TEST",detect_test,[".test"], [:_TestTemplates])
end

```

Then the following code works:

```Julia
using _TestTemplates
using FileIO

save("test.test","Hello, world")
load("test.test") # return "Hello, world"

```

I made [a toy example in github](https://github.com/ehgus/_TestTemplates.jl).
