Click here to Skip to main content
15,902,114 members
Home / Discussions / C#
   

C#

 
GeneralRe: Viewing XML in AxSHDocVW Pin
m_mond11-Mar-03 10:42
m_mond11-Mar-03 10:42 
GeneralRe: Viewing XML in AxSHDocVW Pin
leppie11-Mar-03 10:53
leppie11-Mar-03 10:53 
GeneralRe: Viewing XML in AxSHDocVW Pin
Stephane Rodriguez.11-Mar-03 11:20
Stephane Rodriguez.11-Mar-03 11:20 
QuestionDraw image with alpha blending ? Pin
Wizard_0111-Mar-03 8:54
Wizard_0111-Mar-03 8:54 
GeneralGetting AVI's into a C# Windows Form project Pin
antoine@orchus-tech11-Mar-03 7:38
antoine@orchus-tech11-Mar-03 7:38 
GeneralUsing MemoryStream instead of FileStream problem Pin
LongRange.Shooter11-Mar-03 7:23
LongRange.Shooter11-Mar-03 7:23 
GeneralRe: Using MemoryStream instead of FileStream problem Pin
leppie11-Mar-03 7:38
leppie11-Mar-03 7:38 
GeneralRe: Using MemoryStream instead of FileStream problem Pin
LongRange.Shooter11-Mar-03 9:07
LongRange.Shooter11-Mar-03 9:07 
lippie -- looks like you may have got things reversed. We have working file steam logic we just cannot get the memory stream to work.

Here is what works:
<br />
public static int ZipFilesInto(string zipFileName,string dirPath,string searchPattern,bool recursive, DateTime dateFilter, string basePath)<br />
{<br />
    ZipFile zf=new ZipFile(zipFileName,ZipFileOpenMode.Write);<br />
    zf.BasePath=basePath;<br />
    int ret=zf.Add(dirPath, searchPattern, recursive, dateFilter);<br />
    zf.CloseZipFile();<br />
    return ret;<br />
}<br />

We are trying to replace this with a memory stream. Here is what does not work.
<br />
public static byte[] ZipFilesToMemory(string dirPath,string searchPattern,bool recursive, DateTime dateFilter, string basePath)<br />
{<br />
    MemoryStream m=new MemoryStream();<br />
    ZipFile zf=new ZipFile(m,ZipFileOpenMode.Write);<br />
    zf.BasePath=basePath;<br />
    int ret=zf.Add(dirPath, searchPattern, recursive, dateFilter);<br />
    byte[] buf = new byte[m.Length];<br />
    int ost=0;<br />
    int cnt=0;<br />
    while(true)<br />
    {<br />
	cnt=m.Read(buf,ost,4096);<br />
	if(cnt==0)break;<br />
	ost+=cnt;<br />
    }<br />
    zf.CloseZipFile();<br />
    return buf;<br />
}<br />


And....here are the methods being called:

<br />
		public ZipFile(string zipFilePath,ZipFileOpenMode zom)<br />
		{<br />
			ZipFilePath=zipFilePath;<br />
			OpenZipFile(zom);<br />
		}<br />
		public ZipFile(Stream baseStream,ZipFileOpenMode zom)<br />
		{<br />
			if(zom==ZipFileOpenMode.Write)<br />
			{<br />
				zos = new ZipOutputStream(baseStream);<br />
			}<br />
			else<br />
			{<br />
				zis = new ZipInputStream(baseStream);<br />
			}<br />
		}<br />
		public enum ZipFileOpenMode<br />
		{<br />
			/// <summary><br />
			///	Open the zip for read only to extract or inspect the contents<br />
			/// </summary><br />
			Read,<br />
			/// <summary><br />
			/// Open the file as an output for a new zip file or to add to an existing zip file<br />
			/// </summary><br />
			Write<br />
		}<br />
		public bool OpenZipFile(ZipFileOpenMode zfom)<br />
		{<br />
			if(zfom == ZipFileOpenMode.Read)<br />
				zis = new ZipInputStream(File.OpenRead(ZipFilePath));<br />
			else<br />
				zos = new ZipOutputStream(File.Create(ZipFilePath));<br />
<br />
			return true;<br />
		}<br />
		public bool CloseZipFile()<br />
		{<br />
			if(zis!=null)zis.Close();<br />
			if(zos!=null)zos.Close();<br />
			zis=null;<br />
			zos=null;<br />
			return true;<br />
		}<br />


It appears the developer is treating both the file stream writer and the memory stream writer as equals, which should be correct. In debug, the data in the memory stream is less than the total capacity allocated yet when he persists it to disk it saves the total capacity size.

_____________________________________________
The world is a dangerous place.
Not because of those that do evil,
    but because of those who look on and do nothing.

GeneralRe: Using MemoryStream instead of FileStream problem Pin
leppie11-Mar-03 10:27
leppie11-Mar-03 10:27 
GeneralRe: Using MemoryStream instead of FileStream problem Pin
LongRange.Shooter12-Mar-03 7:13
LongRange.Shooter12-Mar-03 7:13 
GeneralRe: Using MemoryStream instead of FileStream problem Pin
leppie12-Mar-03 8:32
leppie12-Mar-03 8:32 
GeneralAccessing controls of one form from another form Pin
Mazdak11-Mar-03 6:57
Mazdak11-Mar-03 6:57 
GeneralRe: Accessing controls of one form from another form Pin
Zek3vil11-Mar-03 7:07
Zek3vil11-Mar-03 7:07 
GeneralRe: Accessing controls of one form from another form Pin
Mazdak11-Mar-03 7:33
Mazdak11-Mar-03 7:33 
GeneralRe: Accessing controls of one form from another form Pin
Zek3vil11-Mar-03 21:13
Zek3vil11-Mar-03 21:13 
GeneralRe: Accessing controls of one form from another form Pin
Mazdak12-Mar-03 6:34
Mazdak12-Mar-03 6:34 
GeneralUpdate does not work for dataset Pin
Marix11-Mar-03 4:39
Marix11-Mar-03 4:39 
GeneralRe: Update does not work for dataset Pin
leppie11-Mar-03 6:24
leppie11-Mar-03 6:24 
GeneralRe: Update does not work for dataset Pin
Marix11-Mar-03 21:47
Marix11-Mar-03 21:47 
GeneralRe: Update does not work for dataset Pin
Marix12-Mar-03 1:44
Marix12-Mar-03 1:44 
GeneralRe: Update does not work for dataset Pin
leppie13-Mar-03 10:11
leppie13-Mar-03 10:11 
GeneralC# pipe example Pin
Davy Mitchell11-Mar-03 3:39
Davy Mitchell11-Mar-03 3:39 
GeneralCopying NOT Moving a Directory!!!! Pin
jesus4u11-Mar-03 3:13
jesus4u11-Mar-03 3:13 
GeneralRe: Copying NOT Moving a Directory!!!! Pin
Stephane Rodriguez.11-Mar-03 3:43
Stephane Rodriguez.11-Mar-03 3:43 
GeneralRe: Copying NOT Moving a Directory!!!! Pin
jesus4u11-Mar-03 3:48
jesus4u11-Mar-03 3:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.