TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Reply
 
Thread Tools Display Modes
Old 27-09-2007, 01:41 AM   #1
Chris Fink
Guest
 
Posts: n/a
Zip file using a stream

I am trying to make a minor modification to the code below and need some
assistance. Currently this code is using the java.util, java.util.zip, and
java.io assemblies from the vjslib.dll assembly. This code works fine by
taking file(s) from
disk and creating a zip file to disk. I need to modify this code to read a
file from a byte array and then output the zip file to a byte array (all done
in memory instead of disk). The reason for the byte array is that all the
files are being stored in the database in a BLOB field. Any assistance is
appreciated!

private static void Zip(string zipFileName, string[] sourceFile)
{
// TODO: this contains the file retrieved from the database.
Need to load this into the FileOutputStream.
byte[] ba = GetBlob(13); // getblob is a method that queries the DB

// this prepares a zip file for output to disk
FileOutputStream filOpStrm = new FileOutputStream(zipFileName);
ZipOutputStream zipOpStrm = new ZipOutputStream(filOpStrm);

FileInputStream filIpStrm = null;
foreach(string strFilName in sourceFile)
{
// load the file contents into a system.io.filestream
filIpStrm = new FileInputStream(strFilName);
ZipEntry ze = new ZipEntry(Path.GetFileName(strFilName));
zipOpStrm.putNextEntry(ze);
sbyte[] buffer = new sbyte[1024];
int len = 0;
while ((len = filIpStrm.read(buffer)) >= 0)
{
// this writes zip file to disk
//TODO: need to write this stream to a byte array instead of
disk, which I'll insert into the BLOB field.
zipOpStrm.write(buffer, 0, len);

}
}
zipOpStrm.closeEntry();
filIpStrm.close();
zipOpStrm.close();
filOpStrm.close();
}
  Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to stream DRM protected file to Media Server ? troycity via WindowsKB.com Windows Media 0 21-09-2007 06:52 PM
Stream to Playstation 3 iks Windows Media 0 21-09-2007 06:31 PM
Stream video to N95? rab Nokia 0 15-09-2007 03:33 PM
Help with . ASX stream file type, please Al Dykes Windows XP 1 04-09-2007 07:29 AM
Stream recording DefecTalisman Windows Vista All 0 18-08-2007 01:02 AM

Google
 


All times are GMT +5.5. The time now is 06:28 AM.


vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2008, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional