| | |
Problem with DeflateStream class
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 7
Reputation:
Solved Threads: 0
I'm trying to decode a flatencoded pdf stream. I get the exception:
Index was outside the bounds of the array.
I don't understand because I have tried to be really exact.
I Would appreciate your help on this.
Here is the code I'm using.
ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] buffer=encoding.GetBytes(data);
byte[] decomp = Decompress(buffer);
public static byte[] Decompress(byte[] data)
{
MemoryStream input = new MemoryStream();
input.Write(data, 0, data.Length);
input.Position = 0;
DeflateStream gzip = new DeflateStream(input, CompressionMode.Decompress, false);
input.ReadByte();
input.ReadByte();
MemoryStream output = new MemoryStream();
byte[] buff = new byte[64];
int read = -1;
read = gzip.Read(buff, 0, buff.Length);
while (read > 0)
{
output.Write(buff, 0, read);
read = gzip.Read(buff, 0, buff.Length);
}
gzip.Close();
return output.ToArray();
}
If you can't find anything without testing then I can upload the stream file I'm working on.
I managed to decode it with a PHP application so it seams right.
Thanks for you help.
Index was outside the bounds of the array.
I don't understand because I have tried to be really exact.
I Would appreciate your help on this.
Here is the code I'm using.
ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] buffer=encoding.GetBytes(data);
byte[] decomp = Decompress(buffer);
public static byte[] Decompress(byte[] data)
{
MemoryStream input = new MemoryStream();
input.Write(data, 0, data.Length);
input.Position = 0;
DeflateStream gzip = new DeflateStream(input, CompressionMode.Decompress, false);
input.ReadByte();
input.ReadByte();
MemoryStream output = new MemoryStream();
byte[] buff = new byte[64];
int read = -1;
read = gzip.Read(buff, 0, buff.Length);
while (read > 0)
{
output.Write(buff, 0, read);
read = gzip.Read(buff, 0, buff.Length);
}
gzip.Close();
return output.ToArray();
}
If you can't find anything without testing then I can upload the stream file I'm working on.
I managed to decode it with a PHP application so it seams right.
Thanks for you help.
![]() |
Other Threads in the C# Forum
- Previous Thread: Regexp whitespace problem
- Next Thread: C# - How do you pass a common type between 2 web services
| Thread Tools | Search this Thread |
.net 2007 access ado.net algorithm array barchart bitmap box broadcast buttons c# camera check checkbox client color combobox control conversion cs4 csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event eventcloseformc# excel file files form format forms function gdi+ httpwebrequest image index input install ip java label list listbox listener listview load mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox security serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer update usercontrol validation visual visualstudio webbrowser windows winforms wordautomation wpf xml





