473,657 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unzip problem with images

Hi to all,

I am using ICSharpCode.Sha rpZipLib.Zip.

My zip file contains a number of images which when they get unzipped only
contain a partial image. The filesize looks correct.

The unziping is done below it is not clear where the problem is. For int
numberOfBytesTo Read = (int) zipEntryObject. Size; I initially had the
int numberOfBytesTo Read = (int) readStream.leng th but this always gave me
0.

foreach (ZipEntry zipEntryObject in zipFileObject)
{
System.IO.Strea m readStream =
zipFileObject.G etInputStream(z ipEntryObject);
int numberOfBytesTo Read = (int) zipEntryObject. Size;

byte[] bytes = new byte[numberOfBytesTo Read];

readStream.Read (bytes, 0, numberOfBytesTo Read);
System.IO.FileS tream outputStream =
new System.IO.FileS tream(@Director y + zipEntryObject. Name,
System.IO.FileM ode.Create);

outputStream.Wr ite(bytes, 0, numberOfBytesTo Read);
outputStream.Fl ush();
outputStream.Cl ose();

}

Sham.
May 25 '06 #1
1 1239
When reading streams, the better approach (and it does it in the ziplib
docs) is to iterate under Read returns <=0; Read is only guaranteed to
return *some* data; I'm guessing this is the problem. You can also save on
the memory footprint by only needing a small buffer, rather than the entire
file size...

The following function (and override) correctly copiesbetween two streams;
use it instead.
Oh, and consider "using" the streams so that they get disposed instead of
finalised - but since you are closing them this will only make a (genuine)
difference when exceptions are thrown.

Marc

/// <summary>
/// Read all data from one stream into another, in user-defined chunks
/// </summary>
/// <param name="input">St ream to read from</param>
/// <param name="output">T arget stream</param>
/// <param name="bufferSiz e">Chunk size (bytes)</param>
/// <returns>The total number of bytes copied</returns>
private long CopyStream(Stre am input, Stream output, int bufferSize) {
byte[] buffer = new byte[bufferSize];
int bytesRead;
long totalBytes = 0;
while ((bytesRead = input.Read(buff er, 0, bufferSize)) > 0) {
output.Write(bu ffer, 0, bytesRead);
totalBytes += bytesRead;
}
output.Flush();
return totalBytes;
}

/// <summary>
/// Read all data from one stream into another
/// </summary>
/// <param name="input">St ream to read from</param>
/// <param name="output">T arget stream</param>
/// <returns>The total number of bytes copied</returns>
private long CopyStream(Stre am input, Stream output) {
return CopyStream(inpu t, output, 1024);
}
May 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3357
by: Chris | last post by:
Hi Where can I find info on unzipping file with VB.NET. I need to unzip a winzip file with my application Thanks
1
1843
by: Jean Christophe Avard | last post by:
Hi! Finally I figure out what was wrong... "objZipEntry.size = strmFile" I wasn't giving the right file length... But now, I have issue with the unzip function... I can't unzip it, the unzip function return true but its invalid parameter when I try to set the image to the picture box.... Private Overloads Function Unzip(ByVal strSource As String, ByVal strFileToExtract As String, ByRef newms As MemoryStream) As Boolean If...
3
5780
by: SDRoy | last post by:
Hello Can someone tell me how I can unzip a .zip file in C#. The zip file is already there and I just need to unzip..not zip and unzip. -- Thanks, SDRoy
4
6012
by: DataSmash | last post by:
I need to unzip all zip file(s) in the current directory into their own subdirectories. The zip file name(s) always start with the string "usa" and end with ".zip". The code below will make the subdirectory, move the zip file into the subdirectory, but unzips the contents into the root (current) directory. I want the contents of the zip file unloaded into the newly created subdirectory where the zip file is. Any ideas? Thanks.
0
1661
by: Rocky Zhou | last post by:
python unzip At first, I tried to use 'os.popen3("unzip ...") like this: fin, fout, ferr = os.popen3("unzip -o -d %s %s" % (dest, zipfile)) strerr = ferr.read() # This makes the program hanging up if strerr: print >sys.stderr, strerr outlog.error(strerr)
3
2628
by: sdoty044 | last post by:
I am a true n00b... and I just using Python to complete some very small uneventful task, but need help with one last thing. Basically, this I what I am trying to do. make a temp directory (this part I can do) Need help with: ***unzip a JAR file with the complete list of subdirectories w/ files****
5
7036
by: =?Utf-8?B?anVsaW8=?= | last post by:
Hi, I write a program to unzip a Tar file generated on a Unix environment file using SharpZipLib, but returns a error "Header checksum is invalid" when execute the program. This error appears when I try to extract the files. Can any help me where is a sample to unzip a tar file TIA Julio
1
8517
by: olddocks | last post by:
I want to upload a zip file and then extract/unzip it. I am accomplishing this with php exec command. I am calling unzip from php exec command within a php script and it is not extracting files. why? <?php echo exec('unzip file.zip'); ?> i checked apache logs and it says It works perfectly fine when i unzip using SSH command line.. how to fix this problem.
2
6379
by: somsub | last post by:
Hi all, Here is my samle code use strict ; use warnings ; use IO::Uncompress::Unzip ; When I compiled this three lines of code in win32 I got error like below.
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.