piping a http stream through compression and encryption

864 views
Skip to first unread message

Maarten Koopmans

unread,
Jun 13, 2013, 12:29:28 PM6/13/13
to golan...@googlegroups.com
Hi,

See &subject.  I have an http upload that I want to pass through a compression stage and then encrypt.

I can compress or encrypt using io.Copy - I seem to miss how to pipe a writer in e.g. the gzip package to the reader of an encryption stream.

I considered implementing my own buffering stream with goroutines, but I suspect this is one of the things that may be supported from the default libs - once you know "how".

Any feedback or advice greatly appreciated!

Thanks,

Maarten

Gustavo Niemeyer

unread,
Jun 13, 2013, 1:28:02 PM6/13/13
to Maarten Koopmans, golan...@googlegroups.com
On Thu, Jun 13, 2013 at 1:29 PM, Maarten Koopmans
<maarten....@gmail.com> wrote:
> See &subject. I have an http upload that I want to pass through a
> compression stage and then encrypt.
>
> I can compress or encrypt using io.Copy - I seem to miss how to pipe a
> writer in e.g. the gzip package to the reader of an encryption stream.

It's just a matter of stacking the writers. This is a simple tweak of
the example on crypto/cipher, for instance:

http://play.golang.org/p/4CX1J_IYqk

> I considered implementing my own buffering stream with goroutines, but I
> suspect this is one of the things that may be supported from the default
> libs - once you know "how".

Although it's really not necessary for this case, this already exists:

http://blog.labix.org/2013/04/15/unix-like-pipelines-for-go


gustavo @ http://niemeyer.net

Maarten Koopmans

unread,
Jun 13, 2013, 5:27:36 PM6/13/13
to golan...@googlegroups.com, Maarten Koopmans
Hi Gustavo,

> I can compress or encrypt using io.Copy - I seem to miss how to pipe a
> writer in e.g. the gzip package to the reader of an encryption stream.

It's just a matter of stacking the writers. This is a simple tweak of
the example on crypto/cipher, for instance:

    http://play.golang.org/p/4CX1J_IYqk


This is precisely what I needed, thanks!

--Maarten 
Reply all
Reply to author
Forward
0 new messages