Re: Streams



Richard wrote:
I have a typical text file that I have been writing to disk. Afterwards, I zip it up and delete the original.txt file.
Would I be better off writing it to a stream, then using compression routines that support compressing streams then writing to disk. Seems it would speed things up somewhat. We are talking 6 meg text files here.

It would be much tidier, but not necessarily faster - Windows may never actually dump the file to disk during your current method.


Are there any simple examples how to write a text file to a Stream?

That depends on how you want to build the file. I'd:

 list:tstringlist;
 stream:tmemorystream;

 stream:=tmemorystream.create;
  try
   list:=tstringlist.create;
    try
     list.add('Hello!');
     list.add('Line 2');
     list.savetostream(stream);
     stream.seek(0,sofrombeginning); //rewind before compressing
     docompress(stream);
    finally
     list.free;
    end;
  finally
   stream.free;
  end;

Cheers,
Nicholas Sherlock
.



Relevant Pages

  • Re: Reading & Writing in a Stream
    ... > I want to write to a stream, but the data is not byte array. ... > Is another way for this kind of writing and reading? ... to http or to disk. ... you can't - you need to wrap it with a StreamWriter first, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: File Streams
    ... >one line at a time to a disk file and making it comma delimeted at the same ... > I know I could store pointers for the positon I'm at in the array, ... >working array then dump it it may be faster and less hassles, or a stream. ... Generally I have found that the optimum speed is obtained by writing ...
    (alt.comp.lang.borland-delphi)
  • Re: Streams
    ... I'm writing from an Array directly to a Flash Drive. ... So, by writing the array to a stream, compressing from the stream straight ...
    (alt.comp.lang.borland-delphi)
  • Re: Reading & Writing in a Stream
    ... Cor wrote: ... write bytes to disk, one way or other. ... I still say it's irrelevant whether or not the OP's stream is writing ...
    (microsoft.public.dotnet.languages.csharp)
  • Email Attachment
    ... i have a file read in a stream ... and without writing it to disk i want to send it as an attachement, ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)