Telerik Forums
Telerik Document Processing Forum
2 answers
240 views
Hello,

I am trying the ZIP control for silverlight, but i keep having an issue.
I am trying to Compress and Uncompress a stream which is getting read from a WAV file.
the issue is that the size of the stream before compression and after decompression is different. this causes the uncomressed stream to be invalid and therefore not to be played by the basic media element of silverlight.

I am attaching a sample of code to demonstrate the zip and unzip methods that i use.

string wavFilePath = @"C:\1\cheer.wav";
string wavFileNewPath = @"C:\1\cheerNew.wav";
string zipFilePath = @"c:\1\123.zip";
 
private void btnCompress(object sender, RoutedEventArgs e)
{
    FileStream fs = new FileStream(wavFilePath, FileMode.Open);
    SizeBefore.Text = fs.Length.ToString();
    using (ZipPackage zipFile = ZipPackage.CreateFile(zipFilePath))
    {
         zipFile.AddStream(fs, "cheer.wav", ZipCompression.Default, DateTime.Now);
         zipFile.Close(true);
     }       
}
 
private void btnUncompress(object sender, RoutedEventArgs e)
{
     using (ZipPackage zipFile = ZipPackage.OpenFile(zipFilePath, FileAccess.Read))
     {
         ZipPackageEntry zipEntry = zipFile.ZipPackageEntries[0];
         Stream strm = zipEntry.OpenInputStream();
         byte[] Bytes = new byte[strm.Length];
         strm.Read(Bytes, 0, (int)strm.Length);
         using (FileStream fs = new FileStream(wavFileNewPath, FileMode.Create))
         {
              fs.Write(Bytes, 0, Bytes.Length);
              fs.Close();               
         }
    }
 }

I wanted to also note that I did encounter the decompress example which is online here. but it does not help me since dealing with string will not give me the expected result.

Thank you in advance for nay help about this...

kob490.
Koby
Top achievements
Rank 1
 answered on 13 Jun 2012
13 answers
278 views
I am compressing a string on the client (and can uncompress it on the client). Thus, I know it is working.

However, what is the appropriate technical for uncompressing the string once its been sent over to the server?
 
I am using WCF web services.

I've added a reference to Telerik.Windows.Zip but the DLL throws an error when I attempt to create the object:

 

 

 

 

 

Dim inputStream As New ZipInputStream(memStream)

Can the DLL not be used on the server side? If not, how do I uncompress the data?

-Dave

Luc
Top achievements
Rank 1
 answered on 05 Apr 2012
3 answers
188 views
Hello,
I was wondering if I can use ZipLibrary to compress WCF data transfer instead of radcompression,I've found no talks about that nor example...is it possible?

Thanks
Tina Stancheva
Telerik team
 answered on 06 Mar 2012
2 answers
162 views

Hi there,

I've got a small application and now stuck in the task "Appending Files in Zip".

As far as it looks the ZipPackage only allow to Read or Write. Not both.

The Codeblock with the routine

ZipPackage zipPackage;
  
if (File.Exists(appPath + @"\" + currentMonthZip))
{
    Stream stream = File.OpenRead(appPath + @"\" + currentMonthZip);
    zipPackage = ZipPackage.Open(stream, FileAccess.ReadWrite);
}
else
{
    Stream stream = File.Create(appPath + @"\" + currentMonthZip);
    zipPackage = ZipPackage.Create(stream);
}
  
foreach (string folderName in logFoldernames)
{
    string[] listLogs = Directory.GetFiles(appPath + @"\" + folderName);
    foreach (string listLogName in listLogs)
    {
        zipPackage.Add(listLogName, folderName + @"\" + Path.GetFileName(listLogName));
    }
  
    Directory.Delete(appPath + @"\" + folderName);
}

I'm aware that maybe the problem lays here but change the FileAccess or FileMOde ends in exceptions (Stream not for Read/Write)

Stream stream = File.OpenRead(appPath + @"\" + currentMonthZip); 
zipPackage = ZipPackage.Open(stream, FileAccess.ReadWrite);

So what's the suggested approach to open an existing Zip and just attach some new Files in it?

Do I really have to create a temporary zip with old and new content and afterwards delete the old zip and rename the new to the proper name? 

Thanks for any help.

Adrian
Top achievements
Rank 1
 answered on 10 Jan 2012
3 answers
360 views
Hi,

I'm using the PersistenceManager to persist a RadWindow into a database and I would like to know if
it's possible to compress the resulting stream of the SAVE method before save it into my database?

Can you provide me a small example for both scenario?

Here is the scenario 1:
- Persist a RadWindow using the PersistenceManager
- Compress the resulting stream of the SAVE method
- Save the compressed stream into the database

here is the scenraio 2:
- Load the compressed stream from the database
- Uncompress the loaded stream
- Load the RadWindow uncompressed stream

Thank's
Tina Stancheva
Telerik team
 answered on 30 Nov 2011
5 answers
305 views
I have a Silverlight application that is importing Shape files (.shp) and parsing them as streams.  A shape file usually also include other companion files that have the same file name other than having a different extension (such as .dbf and .prj).  

Because I want to be able to import these file groups directly or from within ZIPs, I wrote some logic to first add all the imported files to a list, then explode any imported zip files' file contents into that same list.  When I pass a ZipInputStream to my parsing logic, I get errors and strange behavior that I don't get when I import the files directly.  Here's the error I usually get:

System.IO.EndOfStreamException: Attempted to read past the end of the stream.

What am I doing wrong?  Why can't I just parse the ZipInputStreams the same way I parse the FileStreams that come from the OpenFileDialog?

NOTE: Sample project is available here.  First try importing the sample data files directly (test.shp, test.dbf, test.prj) by multi-selecting them in the OpenFileDialog.  Then, try importing the ZIP file (test.zip) which contains the exact same three files and see the error.

Thanks,
J. Tower
Falafel Support
Top achievements
Rank 1
 answered on 29 Nov 2011
3 answers
405 views
Hi

I want to be able to upload a zip file to the server (using RadUpload) and then extract the files within it to the server once uploaded.

How do i do this?

Many Thanks
Tracey
Tina Stancheva
Telerik team
 answered on 22 Nov 2011
1 answer
185 views
Hello,

I am having a lot of success with this new addition to the Telerik WPF library, however i cannot see how I can add a directory to the archive?
Thanks,

Xavier.
Tina Stancheva
Telerik team
 answered on 30 Sep 2011
1 answer
175 views
How to set password on Saving & opening the zip file.
Viktor Tsvetkov
Telerik team
 answered on 14 Sep 2011
2 answers
329 views
Good day,

      I have a code as follows to compress I just copied it from the documentation:

private string CompressString(string str)
        {
            MemoryStream memoryStream = new MemoryStream();
            ZipCompression method = ZipCompression.Default;
            ZipOutputStream zipOutputStream = new ZipOutputStream(memoryStream, method);
            StreamWriter writer = new StreamWriter(zipOutputStream);
            writer.Write(str);
            writer.Flush();
            return Convert.ToBase64String(memoryStream.ToArray());
        }


  What is missing is to decompress it, I tried the following code but it doesn't give me the correct output

private string UnCompressString(string str)
        {

            MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(str));
            ZipInputStream input = new ZipInputStream(memoryStream);
            StreamReader reader = new StreamReader(input.BaseStream);
            string strData = reader.ReadToEnd();
            return strData;

        }

  When I tried to call the uncompressstring method, it does not give me the original text.

Thanks
Levi
Top achievements
Rank 1
 answered on 07 Sep 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jake
Top achievements
Rank 1
RBarnes
Top achievements
Rank 1
Iron
Iron
Rami
Top achievements
Rank 1
Iron
Veteran
Nathan
Top achievements
Rank 1
Kumeri
Top achievements
Rank 1
Iron
Veteran
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jake
Top achievements
Rank 1
RBarnes
Top achievements
Rank 1
Iron
Iron
Rami
Top achievements
Rank 1
Iron
Veteran
Nathan
Top achievements
Rank 1
Kumeri
Top achievements
Rank 1
Iron
Veteran
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?