Click here to Skip to main content
15,884,879 members
Home / Discussions / C#
   

C#

 
QuestionHelp Regarding OPEN XML, Pin
meetnneel17-Jul-13 6:16
meetnneel17-Jul-13 6:16 
AnswerRe: Help Regarding OPEN XML, Pin
Dave Kreskowiak17-Jul-13 7:24
mveDave Kreskowiak17-Jul-13 7:24 
GeneralRe: Help Regarding OPEN XML, Pin
BillWoodruff17-Jul-13 17:25
professionalBillWoodruff17-Jul-13 17:25 
GeneralRe: Help Regarding OPEN XML, Pin
Dave Kreskowiak17-Jul-13 18:00
mveDave Kreskowiak17-Jul-13 18:00 
GeneralRe: Help Regarding OPEN XML, Pin
BillWoodruff17-Jul-13 18:11
professionalBillWoodruff17-Jul-13 18:11 
GeneralRe: Help Regarding OPEN XML, Pin
Dave Kreskowiak18-Jul-13 2:09
mveDave Kreskowiak18-Jul-13 2:09 
AnswerRe: Help Regarding OPEN XML, Pin
BillWoodruff17-Jul-13 17:28
professionalBillWoodruff17-Jul-13 17:28 
QuestionUsing Binary Serialization and GZip ? Pin
BillWoodruff17-Jul-13 3:14
professionalBillWoodruff17-Jul-13 3:14 
I am successfully using .NET's BinaryFormatter to serialize a very complex object (an instance, at run-time) into a MemoryStream, and I can save that to a file, and then de-serialize the file back into an instance of the object.

Then, I wanted to add compressing the MemoryStream using GZip [1], before saving it to a file.

I am, without compile- or run- time error, using .NET's GZip facility to GZip the created MemoryStream, and then save it to a disk file.

To summarize the save-to-file sequence:

1. use BinaryFormatter to serialize the object to a MemoryStream

2. use GZip to compress the MemoryStream

3. write the Gzipped MemoryStream to disk

I've already learned the hard way that there is a quirk in using GZip in .NET in compressing [^].

I verify that the file is written, and it appears to have been "shrunk" by the GZip facility.

But, when I try to reverse the process, to essentially deserialize (recreate) the object by:

1. reading the Gzipped saved file into a MemoryStream

2. using GZip's Decompress on the MemoryStream

3. using BinaryFormatter to deserialize the MemoryStream, which I then cast into the Type of the original object: fail.

The point I am stuck at is expressed in this code:
C#
// un GZip

// at this point 'newMemoryStream holds the result
// of opening the saved serialized/Gzipped file

using (GZipStream deCompressionStream = new GZipStream(new MemoryStream(), CompressionMode.Decompress))
{
   // here 'deCompressionStream is 'CanRead = 'true, CanWrite = 'false
   // Length property examined at break-point indicates some Exception
   // so you can't write anything into 'deCompressionStream
   // like this:
   // newMemoryStream.CopyTo(deCompressionStream);

   // yes, this will not fail, but doesn't make sense
   // it's inconsistent with the way that Gzipping compression works !
   deCompressionStream.CopyTo(newMemoryStream);
}

BinaryFormatter bFormatter = new BinaryFormatter();

// if you try this using the "doesn't make sense"
// attempt above:
// you'll get a 'stream was not readable' error

object obj = bFormatter.Deserialize(newMemoryStream);
Thanks in advance for any advice.

yours, Bill

[1] I set out to explore using GZip as a way to increase my general knowledge of .NET's stream facilities, and after learning how to successfully use Mehdi Gholam's fastBinaryJSON work here on CP, and using the MiniLZO class in Mehdi's Raptor Document Store.
“Human beings do not live in the objective world alone, nor alone in the world of social activity as ordinarily understood, but are very much at the mercy of the particular language which has become the medium of expression for their society. It is quite an illusion to imagine that one adjusts to reality essentially without the use of language and that language is merely an incidental means of solving specific problems of communication or reflection." Edward Sapir, 1929

AnswerRe: Using Binary Serialization and GZip ? Pin
Richard Deeming17-Jul-13 4:02
mveRichard Deeming17-Jul-13 4:02 
GeneralRe: Using Binary Serialization and GZip ? Pin
BillWoodruff17-Jul-13 15:07
professionalBillWoodruff17-Jul-13 15:07 
AnswerRe: Using Binary Serialization and GZip ? Pin
Eddy Vluggen17-Jul-13 5:07
professionalEddy Vluggen17-Jul-13 5:07 
GeneralRe: Using Binary Serialization and GZip ? Pin
BillWoodruff17-Jul-13 16:52
professionalBillWoodruff17-Jul-13 16:52 
GeneralRe: Using Binary Serialization and GZip ? Pin
Eddy Vluggen18-Jul-13 6:32
professionalEddy Vluggen18-Jul-13 6:32 
GeneralRe: Using Binary Serialization and GZip ? Pin
BillWoodruff18-Jul-13 17:00
professionalBillWoodruff18-Jul-13 17:00 
GeneralRe: Using Binary Serialization and GZip ? Pin
Eddy Vluggen19-Jul-13 7:30
professionalEddy Vluggen19-Jul-13 7:30 
GeneralRe: Using Binary Serialization and GZip ? Pin
harold aptroot18-Jul-13 7:17
harold aptroot18-Jul-13 7:17 
GeneralRe: Using Binary Serialization and GZip ? Pin
BillWoodruff18-Jul-13 17:04
professionalBillWoodruff18-Jul-13 17:04 
AnswerRe: Using Binary Serialization and GZip ? Pin
Ennis Ray Lynch, Jr.17-Jul-13 7:11
Ennis Ray Lynch, Jr.17-Jul-13 7:11 
GeneralRe: Using Binary Serialization and GZip ? Pin
BillWoodruff17-Jul-13 17:02
professionalBillWoodruff17-Jul-13 17:02 
QuestionWebBrowser and swf textbox and button Pin
Member 843530717-Jul-13 2:11
Member 843530717-Jul-13 2:11 
AnswerRe: WebBrowser and swf textbox and button Pin
Amir Mohammad Nasrollahi29-Jul-13 6:33
professionalAmir Mohammad Nasrollahi29-Jul-13 6:33 
Questionviewing and printing a pdf on different browser Pin
tasumisra17-Jul-13 0:25
tasumisra17-Jul-13 0:25 
AnswerRe: viewing and printing a pdf on different browser Pin
Bernhard Hiller17-Jul-13 21:43
Bernhard Hiller17-Jul-13 21:43 
GeneralRe: viewing and printing a pdf on different browser Pin
Amir Mohammad Nasrollahi29-Jul-13 6:40
professionalAmir Mohammad Nasrollahi29-Jul-13 6:40 
AnswerRe: viewing and printing a pdf on different browser Pin
Amir Mohammad Nasrollahi29-Jul-13 6:40
professionalAmir Mohammad Nasrollahi29-Jul-13 6:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.