添加压缩 [英] Adding compression

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

问题描述

您好,

我想将压缩添加到内存流并将其保存在Oracle

数据库中。这是我到目前为止的代码:


//将Word文档保存到二进制字段,

MemoryStream dataStream = new MemoryStream();

doc.Save(dataStream,SaveFormat.Doc);


//现在压缩它

GZipStream compressedZipStream = new GZipStream(dataStream,

CompressionMode.Compress);


//现在存储到文档附件

row [" DOCUMENT"] = compressedZipStream。 < ---------我怎么能

在这里转储所有字节?


我需要第四行的帮助。我正在使用stream.ToArray()来分配

,但压缩的ZipStream不可用。


如何存储压缩的zip流这一行?


tia,

机会。

解决方案

< blockquote> 4月4日下午2:01,机会 < cha ... @ crwmail.comwrote:


Hello,

我想将压缩添加到内存流并保存到一个Oracle

数据库。这是我到目前为止的代码:


//将Word文档保存到二进制字段,

MemoryStream dataStream = new MemoryStream();

doc.Save(dataStream,SaveFormat.Doc);


//现在压缩它

GZipStream compressedZipStream = new GZipStream(dataStream,

CompressionMode.Compress);


//现在存储到文档附件

row [" DOCUMENT"] = compressedZipStream。 < ---------我怎么能

在这里转储所有字节?


我需要第四行的帮助。我正在使用stream.ToArray()来分配

,但压缩的ZipStream不可用。


如何存储压缩的zip流排?



你没有正确订购。你想设置GZipStream

写入MemoryStream,然后告诉你的文件将
保存到GZipStream中,然后关闭两个流,*然后*调用ToArray。

目前你没有压缩任何东西。


Jon


什么呼叫实际上是压缩吗?


4月4日上午8:23,Jon Skeet [C#MVP] < s ... @ pobox.comwrote:


4月4日下午2:01,机会 < cha ... @ crwmail.com写道:


您好,

我想添加压缩到内存流并将其保存在Oracle

数据库中。这是我到目前为止的代码:


//将Word文档保存到二进制字段,

MemoryStream dataStream = new MemoryStream();

doc.Save(dataStream,SaveFormat.Doc);


//现在压缩它

GZipStream compressedZipStream = new GZipStream(dataStream,

CompressionMode 。压缩);


//现在存储到文档附件

row [" DOCUMENT"] = compressedZipStream。 < ---------我怎样才能将
转储到这里的所有字节?


我需要第四行的帮助。我正在使用stream.ToArray()来分配

,但压缩的ZipStream不可用。


如何将压缩的zip流存储在行中?



你没有正确订购。你想设置GZipStream

写入MemoryStream,然后告诉你的文件将
保存到GZipStream中,然后关闭两个流,*然后*调用ToArray。

目前你没有压缩任何东西。


Jon-隐藏引用文字 -


- 显示引用文本 -



4月4日下午4:42,机会 < cha ... @ crwmail.comwrote:


压缩实际调用了什么?



当您写入GZipStream时,它会将压缩数据(在

缓冲之后等)写入您在构造函数中提供的流中。

压缩有效地发生在幕后,没有你不必说'b $ b'不得不说立即压缩。但是,您必须关闭

流,以便它可以写出最终的缓冲数据。


Jon


Hello,
I want to add compression to a memory stream and save it in an Oracle
database. This is the code I have so far:

//save the Word document to a binary field,
MemoryStream dataStream = new MemoryStream();
doc.Save(dataStream, SaveFormat.Doc);

//now compress it
GZipStream compressedZipStream = new GZipStream(dataStream,
CompressionMode.Compress);

//now store to document attatchment
row["DOCUMENT"] = compressedZipStream. <---------How can I
dump all the bytes here?

I need help with the fourth line. I was using stream.ToArray() to make
the assignment but that is not available for the compressedZipStream.

How can I store the compressed zip stream in the row?

tia,
chance.

解决方案

On Apr 4, 2:01 pm, "chance" <cha...@crwmail.comwrote:

Hello,
I want to add compression to a memory stream and save it in an Oracle
database. This is the code I have so far:

//save the Word document to a binary field,
MemoryStream dataStream = new MemoryStream();
doc.Save(dataStream, SaveFormat.Doc);

//now compress it
GZipStream compressedZipStream = new GZipStream(dataStream,
CompressionMode.Compress);

//now store to document attatchment
row["DOCUMENT"] = compressedZipStream. <---------How can I
dump all the bytes here?

I need help with the fourth line. I was using stream.ToArray() to make
the assignment but that is not available for the compressedZipStream.

How can I store the compressed zip stream in the row?

You''re not ordering things correctly. You want to set the GZipStream
up to write into the MemoryStream, then tell your document to save
into the GZipStream, then close both streams, *then* call ToArray.
Currently you''re not compressing anything.

Jon


What call actually does the compression?

On Apr 4, 8:23 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:

On Apr 4, 2:01 pm, "chance" <cha...@crwmail.comwrote:


Hello,
I want to add compression to a memory stream and save it in an Oracle
database. This is the code I have so far:

//save the Word document to a binary field,
MemoryStream dataStream = new MemoryStream();
doc.Save(dataStream, SaveFormat.Doc);

//now compress it
GZipStream compressedZipStream = new GZipStream(dataStream,
CompressionMode.Compress);

//now store to document attatchment
row["DOCUMENT"] = compressedZipStream. <---------How can I
dump all the bytes here?

I need help with the fourth line. I was using stream.ToArray() to make
the assignment but that is not available for the compressedZipStream.

How can I store the compressed zip stream in the row?


You''re not ordering things correctly. You want to set the GZipStream
up to write into the MemoryStream, then tell your document to save
into the GZipStream, then close both streams, *then* call ToArray.
Currently you''re not compressing anything.

Jon- Hide quoted text -

- Show quoted text -



On Apr 4, 4:42 pm, "chance" <cha...@crwmail.comwrote:

What call actually does the compression?

When you write to a GZipStream, it writes the compressed data (after
buffering etc) to the stream you give it in the constructor. The
compression effectively happens behind the scenes, without you ever
having to say "compress now". You do, however, have to close the
stream so it can write the final buffered data out.

Jon


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

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