What would be the most simple/elegant way to have (de)compression enabled on 
all data sent/received over a socket ? In go it appears that it's as simple as: 
.. code-block:: go

> conn, err := net.Dial("tcp", "localhost:8080")
> 
> `if err != nil ...`
> 
> gzipWriter := gzip.NewWriter(conn) message := "Hello, this is compressed 
> data!" _, err = gzipWriter.Write([]byte(message))

similary in rust: .. code-block:: rust

> let stream = TcpStream::connect("127.0.0.1:8080")?; let mut encoder = 
> GzEncoder::new(stream, Compression::default());
> 
> let message = "Hello, this is compressed data!"; 
> encoder.write_all(message.as_bytes())?;

Well, these examples use a separate construct/writer for encapsulating the 
compression operations, but perhaps there's ways around to make it transparent, 
so that you'd use the standard syntax to write to sockets and get compressed 
data.

Could we have something like this in nim as well, given that it doesn't seem to 
support interfaces ? Inherit from Socket type maybe and add custom procs that 
wrap around the existing send/recv ? Use socketstreams instead of socket to 
write, but nim-lang/zip module only seems to expose a filestream ? zippy also 
doesn't support streams yet.

Reply via email to