GZipStream写入压缩字节 [英] GZipStream compressed bytes written

查看:146
本文介绍了GZipStream写入压缩字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GZipStream时,有没有办法知道写了多少个压缩字节?


例如:


//" buffer"是来自文本文件的数据

//" offset"是0

//计数是100


stream.Write(缓冲区,偏移量,计数);


这将把压缩数据写入底层数据存储。有没有办法得到这些数据的长度?


注意:我知道你可以使用MemoryStream来获得大小,但效率很低。

解决方案


使用GZipStream时,有没有办法知道写了多少个压缩字节?

例如:


//" buffer"是来自文本文件的数据

//" offset"是0

//计数是100


stream.Write(缓冲区,偏移量,计数);


这将把压缩数据写入底层数据存储。有没有办法得到这些数据的长度?


注意:我知道你可以使用MemoryStream来获得大小但效率低下。



你能解释一下吗?我不知道我是否正确......但是我可以解释一下......


" count"是压缩的字节数...

展开 | 选择 | Wrap | 行号


在我的例子中,count是未压缩的大小。因此,100个未压缩的字节传递到流中,但流在将其发送到底层数据源之前压缩它们。我想知道有多少字节被发送到底层源。


查看底层流的大小?

展开 < span class =codeDivider> | 选择 | Wrap | Line编号

When using a GZipStream, is there any way to know how many compressed bytes were written?

For example:

// "buffer" is data from a text file
// "offset" is 0
// "count" is 100

stream.Write(buffer, offset, count);

This is going to write the compressed data to the underlying data store. Is there any way to get the length of this data?

Note: I know you can use a MemoryStream to get the size but this inefficient.

解决方案

When using a GZipStream, is there any way to know how many compressed bytes were written?
For example:

// "buffer" is data from a text file
// "offset" is 0
// "count" is 100

stream.Write(buffer, offset, count);

This is going to write the compressed data to the underlying data store. Is there any way to get the length of this data?

Note: I know you can use a MemoryStream to get the size but this inefficient.

could you explain more? i dont know whether i got u right... but heres wat i can explain....

"count" is number of bytes compressed...

Expand|Select|Wrap|Line Numbers


In my example, "count" was the uncompressed size. So 100 uncompressed bytes pass into the stream, but the stream compresses them before sending it to the underlying data source. I want to know how many bytes are sent to the underlying source.


Look at the underlying stream''s size?

Expand|Select|Wrap|Line Numbers


这篇关于GZipStream写入压缩字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆