Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-06

buffered filestream

13 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner

Hi,

Is there already a buffered file stream in the fpc sources? Or maybe a generic buffered input stream that can be used with TFileStream?

Mattias

Mattias Gaertner
to Zaher Dirkey
Show quoted text 13 lines
On Sun, Jun 10, 2012 at 4:00 PM, Mattias Gaertner < > wrote: > Hi, > > Is there already a buffered file stream in the fpc sources? > Or maybe a generic buffered input stream that can be used with > TFileStream? > > > check mine, http://minilib.svn.sourceforge.net/viewvc/minilib/trunk/lib/mnStreams.pas?view=markup

Thanks, that seems to be a nice sequential text file reader/writer.

That's not what I search. I will try to be more specific:

I want to pass the stream to a binary reader, which skips big parts of the stream. It can seek backwards and the files can be several GB, so I need the int64 read/write/seek.

Maybe the word "buffer" is wrong, maybe "cache" is better.

Preferably the buffer size can be set

Mattias Gaertner
to Alexander Shishkin
Show quoted text 7 lines
10.06.2012 18:40, Mattias Gaertner пишет: > I want to pass the stream to a binary reader, which skips big > parts of the stream. It can seek backwards and the files can be several > GB, so I need the int64 read/write/seek. Do you mean buffered random access

yes

(smth like disk access in DBMS)?

Well, not as sophisticated as an DBMS. Just a cache, that accelerates small sequential reads.

Mattias

Mattias Gaertner
to Michael Van Canneyt: Yes. See fcl-base/src/bufstream.pp. It is even documented on…
Show quoted text 9 lines
On Sun, 10 Jun 2012, Mattias Gaertner wrote: > Hi, > > Is there already a buffered file stream in the fpc sources? Yes.

:)
I guessed so.

> Or maybe a generic buffered input stream that can be used with > TFileStream? See fcl-base/src/bufstream.pp.

Ah, abbreviations. BufStream.

Show quoted text 5 lines
It is even documented on http://www.freepascal.org/docs-html/fcl/bufstream/index.html Amazing, don't you think ? ;-)

The fpc sources are always amazing.

Mattias

Mattias Gaertner
to Mattias Gaertner
Show quoted text 10 lines
On Sun, 10 Jun 2012 16:54:30 +0200 (CEST) Michael Van Canneyt wrote: [...] > It is even documented on > > http://www.freepascal.org/docs-html/fcl/bufstream/index.html > > Amazing, don't you think ? ;-) The fpc sources are always amazing.

Maybe I miss something:

TReadBufStream.Seek calls FakeSeekForward, which calls Discard, which reads everything up to the position.
This is the right solution for pipes and small files, but for big files I need a real Seek.

Can TReadBufStream be extended with a property or should I create a new class?

Mattias

Alexander Shishkin
to Mattias Gaertner: On Sun, 10 Jun 2012 19:08:40 +0400 yes Well, not as sophisticated as an DBMS. Just a…

10.06.2012 20:20, Mattias Gaertner пишет:

Show quoted text 17 lines
On Sun, 10 Jun 2012 19:08:40 +0400 Alexander Shishkin wrote: > 10.06.2012 18:40, Mattias Gaertner пишет: > >> I want to pass the stream to a binary reader, which skips big >> parts of the stream. It can seek backwards and the files can be several >> GB, so I need the int64 read/write/seek. > > Do you mean buffered random access yes > (smth like disk access in DBMS)? Well, not as sophisticated as an DBMS. Just a cache, that accelerates small sequential reads.

Only because yours is readonly. I dont know your real task, but I`m afraid you will have to implement this cache from scratch.

Michael Van Canneyt
to Mattias Gaertner: On Sun, 10 Jun 2012 18:24:14 +0200 Maybe I miss something: TReadBufStream.Seek calls…
Mattias Gaertner wrote 23 lines
On Sun, 10 Jun 2012 18:24:14 +0200 Mattias Gaertner wrote: > On Sun, 10 Jun 2012 16:54:30 +0200 (CEST) > Michael Van Canneyt wrote: > [...] >> It is even documented on >> >> http://www.freepascal.org/docs-html/fcl/bufstream/index.html >> >> Amazing, don't you think ? ;-) > > The fpc sources are always amazing. Maybe I miss something: TReadBufStream.Seek calls FakeSeekForward, which calls Discard, which reads everything up to the position. This is the right solution for pipes and small files, but for big files I need a real Seek. Can TReadBufStream be extended with a property or should I create a new class?

Feel free to extend the existing classes. The classes are by no means set in stone...

They did the job for me, but use cases vary...

Michael.

Mattias Gaertner
to Martin Schreiber
Show quoted text 9 lines
On Sunday 10 June 2012 15:00:20 Mattias Gaertner wrote: > Hi, > > Is there already a buffered file stream in the fpc sources? > Or maybe a generic buffered input stream that can be used with > TFileStream? > MSEgui has a bufstream too: tcustombufstream in lib/common/kernel/msestream.pas, I don't know if it fits your needs.

Looks promising. :)

Mattias