# Append to zipped CSV file

**URL:** https://discourse.julialang.org/t/append-to-zipped-csv-file/40321
**Category:** General Usage
**Created:** [May 28, 2020, 8:08am UTC](https://discourse.julialang.org/t/append-to-zipped-csv-file/40321 "2020-05-28T08:08:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![HenrikM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrikm/32/17975_2.png) [@HenrikM](https://discourse.julialang.org/u/HenrikM)
#### Post date: [May 28, 2020, 8:08am UTC](https://discourse.julialang.org/t/append-to-zipped-csv-file/40321/1 "2020-05-28T08:08:26Z")

</div>

Hello,

I have a program that outputs numerical data. Currently I’m appending into a CSV file so that the progress is saved even if the program is suddenly terminated. Please find the MWE below.

How could I output to an zipped CSV file? I have looked at various packages but could no make it work.

```julia
using DelimitedFiles

open("output.csv", write=true, truncate=true) do io
end

x = zeros(100)
for sdx = 1:1000
    # Compute x .... takes minutes.
    x .= randn(100)

   open("output.csv", write=true, append=true) do io
        writedlm(io, vec(x)', ',')
    end
end

```

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [May 28, 2020, 9:02am UTC](https://discourse.julialang.org/t/append-to-zipped-csv-file/40321/2 "2020-05-28T09:02:24Z")

</div>

I think that gz supports appending:

1. you just open a stream to append to a file,
2. make a gzip output stream, eg with [CodecZlib.jl](https://github.com/JuliaIO/CodecZlib.jl),
3. write to that stream.

Make sure to test this for critical data though.

---

<div class="post-metadata">

### Author: ![HenrikM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrikm/32/17975_2.png) [@HenrikM](https://discourse.julialang.org/u/HenrikM)
#### Post date: [May 28, 2020, 10:04am UTC](https://discourse.julialang.org/t/append-to-zipped-csv-file/40321/3 "2020-05-28T10:04:17Z")

</div>

Thank you for pointing me in the right direction!

```julia
using CodecZlib
using DelimitedFiles

open("output.csv.gz", write=true, truncate=true) do io                                                                                             
end                                                                                                                                              

x = zeros(100)
for sdx = 1:1000
    # Compute x .... takes minutes.
    x .= randn(100)

    fout = open("output.csv.gz", write=true, append=true)
    fout = GzipCompressorStream(fout)
    writedlm(fout, vec(x)', ',')
    close(fout)
end

```

---

<div class="post-metadata">

### Author: ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)
#### Post date: [May 28, 2020, 1:19pm UTC](https://discourse.julialang.org/t/append-to-zipped-csv-file/40321/4 "2020-05-28T13:19:13Z")

</div>

thanks!

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [May 28, 2020, 1:33pm UTC](https://discourse.julialang.org/t/append-to-zipped-csv-file/40321/5 "2020-05-28T13:33:42Z")

</div>

> [@HenrikM](#):
>
> How could I output to an zipped CSV file?

Another options is to output to a binary format like [JDF](https://github.com/xiaodaigh/JDF.jl), Parquet or feather via Parquet.jl and Feather.jl. You will get better features like selectively load columns and compressed file size (for parquet and JDF).
