Re: probably not an Indy question

Giganews Newsgroups
Subject: Re: probably not an Indy question
Posted by:  Remy Lebeau (TeamB) (
Date: Wed, 29 Dec 2004

"xdiscent" <xdisce…> wrote in message

> How do I temporarily write data to disk while the
> download aint finished yet?

You could just use a TFileStream instead of a TMemoryStream.  By default,
file writing is buffered by the OS and written to disk periodically.

If you do not want to rely on the OS, however, then you will have to write
your own TStream class that explicitally flushes its internal data to disk
periodically. For example:

    #define MEGABYTE 1048576

    class TMyFileStream : public TFileStream
        int FNextFlushSize;
        __fastcall TMyFileStream(const AnsiString FileName, Word Mode)
            : TFileStream(FileName, Mode), FNextFlushSize(MEGABYTE)

        virtual int __fastcall Write(const void *Buffer, int Count)
            int Result = TFileStream::Write(Buffer, Count);
            if( Result > 0 )
                int iSize = Size;
                if( iSize >= FNextFlushSize )
                    FNextFlushSize = ((iSize + MEGABYTE) - (iSize %
            return Result;

    #include <memory>

    std::auto_ptr<TIdHTTP> IdHttpClient(new TIdHTTP(NULL));
    std::auto_ptr<TMyFileStream> FStream(new TMyFileStream(cFileName,
    IdHttpClient->Get(strUrl, FStream.get());




In response to

probably not an Indy question posted by xdiscent on Thu, 30 Dec 2004