TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Thang
NA
3
0
DeflateStream??
Apr 1 2009 7:47 PM
I try to write a compression application using Deflate Algorithm. However, when my compressed file is larger than my original file. Below is my code. I use window form so here are some clarifications. I use openFileDialog to choose a file, so openFileDialog.FileName hold the path. I write the compressed bytes to a memory stream. When it done, it check the length of my FileStream and my MemoryStream. The length of my MemoryStream is a lot bigger, which does not make any sense at all
infile = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] buffer = new byte[infile.Length];
//Read From the file
int count1 = infile.Read(buffer, 0, buffer.Length);
if (count1 != buffer.Length)
{
MessageBox.Show("Cannot Read From File");
infile.Close();
return;
}
infile.Close();
MemoryStream ms = new MemoryStream();
//Use this newly memory stream for the compressed data
DeflateStream compressedZipStream = new DeflateStream(ms, CompressionMode.Compress, true);
//Write data from the buffer array into the stream
compressedZipStream.Write(buffer, 0, buffer.Length);
//Close the stream
compressedZipStream.Close();
txtOriginal.Text = buffer.Length.ToString();
txtCompressed.Text = ms.Length.ToString();
Reply
Answers (
3
)
how to calculate a parsed expression (new to programming)
C# TableAdapters