What is NoCompression?

I am trying to use gzip package - compress/gzip - Go Packages and it works as expected when used DefaultCompression and I tried using NoCompression and I found similar with default one.

So, what does NoCompression do? I expected it should not compress, but it’s compressing.

Can you share more information about the compression ratio or the file types you are trying to compress?
Are you trying to compress an already compressed file?

I am just trying to understand what it does? I should expect some ratio of compression or no compression at all?

Level 0 (NoCompression) does not attempt any compression; it only adds the necessary DEFLATE framing.

Data compression ratio:

1 Like

In the context of the compress/gzip package in Go, the NoCompression constant is one of the compression levels provided by the package. When you set the compression level to NoCompression, it means that the gzip package will not apply any compression to the data being processed.

By default, the compress/gzip package uses a compression level called DefaultCompression, which provides a balanced trade-off between compression ratio and speed. However, when you specify NoCompression as the compression level, the gzip package will simply store the input data without applying any compression algorithm.

Setting the compression level to NoCompression can be useful in situations where you want to use the gzip package to write or read data in the gzip format, but you don’t want the data to be compressed. This could be applicable when you need to interface with systems or protocols that expect data in the gzip format but don’t require compression.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.