Click here to Skip to main content
15,887,175 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to get the user defined method Pin
OriginalGriff21-Sep-15 0:51
mveOriginalGriff21-Sep-15 0:51 
GeneralRe: How to get the user defined method Pin
vijay kumar21-Sep-15 20:33
vijay kumar21-Sep-15 20:33 
AnswerRe: How to get the user defined method PinPopular
BillWoodruff21-Sep-15 2:48
professionalBillWoodruff21-Sep-15 2:48 
GeneralRe: How to get the user defined method Pin
Eddy Vluggen21-Sep-15 5:22
professionalEddy Vluggen21-Sep-15 5:22 
GeneralRe: How to get the user defined method Pin
vijay kumar21-Sep-15 20:32
vijay kumar21-Sep-15 20:32 
QuestionWrite an algorithm to add and multiply two large integers, which cannot be represented by built-in types Pin
Nadeem Shaikh20-Sep-15 5:51
Nadeem Shaikh20-Sep-15 5:51 
AnswerRe: Write an algorithm to add and multiply two large integers, which cannot be represented by built-in types Pin
OriginalGriff20-Sep-15 6:04
mveOriginalGriff20-Sep-15 6:04 
QuestionProblem Solved: DataContract/WCF/GZip from .gz file to memory stream to object without creating a new file ? Pin
BillWoodruff20-Sep-15 0:31
professionalBillWoodruff20-Sep-15 0:31 
update: examining the value of the MemoryStream's 'Position property after the decompressed GZipStream was put into it with 'CopyTo showed it to be set to the length of the decompressed GZipStream: setting the MemoryStream's 'Position property to #0 resulted in being able to correctly call Serializer.ReadObject on the MemoryStream and create the desired outcome.

Interesting that in all the searching/reading I did here and on StackOverFlow, I came across no mention of this. Time for a Tip/Trick ? Smile | :)

~

Serializing a class-instance/object using WCF [DataContract] and [DataMember] Attributes is very easy; compressing it with the GZip library, and saving the compressed stream to a file is straightforward: no problems.

Currently my working code for de-serialization from GZip file does the following:
1. open the saved .gz file in the standard way

2. create a new file to hold the un-gzipped .xml whose name is the same as the GZip file, with the .gz extension replaced with .xml.

// compressedstuff.gz => compressedstuff.xml

3. create a new GZip compression stream with Decompress option

4. copy the Gzip compression stream into the new file

5. re-create the "object" in the standard way from file using WCF Serializer
What I want to do is go from the uncompressed GZip file directly to using the WCF Serializer to "resurrect" the object without creating a new file. This code dies with the error "Unexpected end of file:"
using System.Runtime.Serialization;
using System.IO;
using System.IO.Compression;

public static SomeClass GZToObject(string gzFilePath)
{ 
    DataContractSerializer serializer = new DataContractSerializer(typeof(SomeClass));

    SomeClass someClassInstance = null;
    
    FileInfo fileToDecompress = new FileInfo(gzFilePath);
    
    using (MemoryStream xmlStream = new MemoryStream())
    {
        using (GZipStream deCompStream = new GZipStream(File.Open(gzFilePath, FileMode.Open), CompressionMode.Decompress, true))
        {
            deCompStream .CopyTo(xmlStream);
            deCompStream .Close(); // using 'Close here fixes a common problem with GZipStream
            
            // set breakpoint here: xmlStream appears to be valid de-compressed XML
            
            // error here: unexpected end of file
            someClassInstance = (SomeClass) serializer.ReadObject(xmlStream);
        }
    }
    
    return someClassInstance;
}
Is it possible that using GZip facilities requires creating a 'temp file ?

thanks, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.


modified 20-Sep-15 9:33am.

GeneralRe: DataContract/WCF/GZip from .gz file to memory stream to object without creating a new file ? Pin
Wendelius20-Sep-15 0:51
mentorWendelius20-Sep-15 0:51 
GeneralRe: DataContract/WCF/GZip from .gz file to memory stream to object without creating a new file ? Pin
BillWoodruff20-Sep-15 2:47
professionalBillWoodruff20-Sep-15 2:47 
AnswerRe: DataContract/WCF/GZip from .gz file to memory stream to object without creating a new file ? Pin
Wendelius20-Sep-15 7:16
mentorWendelius20-Sep-15 7:16 
AnswerRe: Problem Solved: DataContract/WCF/GZip from .gz file to memory stream to object without creating a new file ? Pin
Richard Deeming21-Sep-15 2:06
mveRichard Deeming21-Sep-15 2:06 
Questionhow to change font size in a richtextbox without selecting the text Pin
Member 1100213719-Sep-15 8:54
Member 1100213719-Sep-15 8:54 
QuestionRe: how to change font size in a richtextbox without selecting the text Pin
Eddy Vluggen19-Sep-15 9:10
professionalEddy Vluggen19-Sep-15 9:10 
AnswerRe: how to change font size in a richtextbox without selecting the text Pin
Member 1100213719-Sep-15 9:15
Member 1100213719-Sep-15 9:15 
GeneralRe: how to change font size in a richtextbox without selecting the text Pin
Eddy Vluggen19-Sep-15 9:20
professionalEddy Vluggen19-Sep-15 9:20 
AnswerRe: how to change font size in a richtextbox without selecting the text Pin
BillWoodruff19-Sep-15 13:48
professionalBillWoodruff19-Sep-15 13:48 
QuestionRE-GET and SET PROPERTY Pin
Member 1116162518-Sep-15 19:32
Member 1116162518-Sep-15 19:32 
AnswerRe: RE-GET and SET PROPERTY Pin
Wendelius18-Sep-15 19:41
mentorWendelius18-Sep-15 19:41 
AnswerRe: RE-GET and SET PROPERTY Pin
Eddy Vluggen18-Sep-15 21:03
professionalEddy Vluggen18-Sep-15 21:03 
AnswerRe: RE-GET and SET PROPERTY Pin
OriginalGriff18-Sep-15 21:34
mveOriginalGriff18-Sep-15 21:34 
AnswerRe: RE-GET and SET PROPERTY Pin
Gilbert Consellado19-Sep-15 6:17
professionalGilbert Consellado19-Sep-15 6:17 
Question[SOLVED]: Not Getting Proper Output From Compiled EXE File Pin
Bastar Media18-Sep-15 1:18
Bastar Media18-Sep-15 1:18 
AnswerRe: Not Getting Proper Output From Compiled EXE File Pin
Pete O'Hanlon18-Sep-15 1:42
mvePete O'Hanlon18-Sep-15 1:42 
AnswerRe: Not Getting Proper Output From Compiled EXE File Pin
GuyThiebaut18-Sep-15 1:52
professionalGuyThiebaut18-Sep-15 1:52 

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.