BufferedFileStream#

Qualified name: delphivcl.BufferedFileStream

class BufferedFileStream#

Bases: FileStream

TBufferedFileStream adds buffering support to TFileStream. TBufferedFileStream optimizes multiple consecutive small reads or writes. However, TBufferedFileStream can be used as a drop-in replacement for TFileStream, enabling applications to read from and write to a file on a disk.

Note: TBufferedFileStream will not give performance gain for random position reads or writes, or large reads or writes.

Methods

Create

Creates an instance of TBufferedFileStream.

Destroy

Destroys this instance of TBufferedFileStream.

FlushBuffer

Writes the buffered data that have not yet been written to the file.

Free

Frees the Wrapped Delphi Object

InheritsFrom

Returns True if Delphi Object is or inherits from ClassName

Read

Reads up to Count bytes of data from the resource associated with the handle stream into Buffer.

ReadBytes

Read content as bytes.

ReadFloat

Read content as float.

ReadInt

Read content as integer.

ReadString

Read content as string.

Seek

Resets the current position of the handle stream.

SetProps

Sets several properties in one call

ToList

If the object is a container (TStrings, TComponent...), it returns the content of the sequence as a Python list object.

ToTuple

If the object is a container (TStrings, TComponent...), it returns the content of the sequence as a Python tuple object.

Write

Writes Count bytes from the Buffer to the current position in the resource.

WriteBytes

Write content as bytes.

WriteFloat

Write content as float.

WriteInt

Write content as integer.

WriteString

Write content as string.

Attributes

ClassName

Returns the TObject.ClassName

FileName

Preserves the file name of the file associated with the file stream.

Handle

Specifies the handle for the communications resource the stream reads from and writes to.

Position

Indicates the current offset into the stream for reading and writing.

Size

Indicates the size in bytes of the stream.

ClassName#

Returns the TObject.ClassName

Create(AFileName: string, Mode: Word, BufferSize: Integer)#

Creates an instance of TBufferedFileStream. Call Create to instantiate a file stream for reading from or writing to the named file. Specify the name of the file and the way the file should be opened as parameters. The Mode parameter indicates how the file is to be opened. The Mode parameter consists of an open mode and (possibly) a share mode or’ed together. The open mode must be one of the following values:

Value

Meaning

Declared In

fmCreate

Create a file with the given name. If a file with the given name exists, override the existing file and open it in write mode.

System.Classes

fmOpenRead

Open the file for reading only.

System.SysUtils

fmOpenWrite

Open the file for writing only. Writing to the file completely replaces the current contents.

System.SysUtils

fmOpenReadWrite

Open the file to modify the current contents rather than replace them.

System.SysUtils

The share mode must be one of the following values:

Value

Meaning

Declared In

fmShareCompat

Sharing is compatible with the way FCBs are opened.

System.SysUtils

fmShareExclusive

Other applications cannot open the file for any reason.

System.SysUtils

fmShareDenyWrite

Other applications can open the file for reading but not for writing.

System.SysUtils

fmShareDenyRead

Other applications can open the file for writing but not for reading.

System.SysUtils

fmShareDenyNone

No attempt is made to prevent other applications from reading from or writing to the file.

System.SysUtils

Note: On Windows, the Rights parameter is ignored. The BufferSize parameter determines the size of the buffer used to read from or write to the file. If the file cannot be opened, Create raises an exception. Creates an instance of TBufferedFileStream. Call Create to instantiate a file stream for reading from or writing to the named file. Specify the name of the file and the way the file should be opened as parameters. The Mode parameter indicates how the file is to be opened. The Mode parameter consists of an open mode and (possibly) a share mode or’ed together. The open mode must be one of the following values:

Value

Meaning

Declared In

fmCreate

Create a file with the given name. If a file with the given name exists, override the existing file and open it in write mode.

System.Classes

fmOpenRead

Open the file for reading only.

System.SysUtils

fmOpenWrite

Open the file for writing only. Writing to the file completely replaces the current contents.

System.SysUtils

fmOpenReadWrite

Open the file to modify the current contents rather than replace them.

System.SysUtils

The share mode must be one of the following values:

Value

Meaning

Declared In

fmShareCompat

Sharing is compatible with the way FCBs are opened.

System.SysUtils

fmShareExclusive

Other applications cannot open the file for any reason.

System.SysUtils

fmShareDenyWrite

Other applications can open the file for reading but not for writing.

System.SysUtils

fmShareDenyRead

Other applications can open the file for writing but not for reading.

System.SysUtils

fmShareDenyNone

No attempt is made to prevent other applications from reading from or writing to the file.

System.SysUtils

Note: On Windows, the Rights parameter is ignored. The BufferSize parameter determines the size of the buffer used to read from or write to the file. If the file cannot be opened, Create raises an exception.

Destroy()#

Destroys this instance of TBufferedFileStream.

FlushBuffer()#

Writes the buffered data that have not yet been written to the file. When using a buffered file stream, call FlushBuffer to write to the file the data from the buffer that are still not written. Once you call FlushBuffer, the buffer will remain empty until the next read or write operation.

Free()#

Frees the Wrapped Delphi Object

InheritsFrom(ClassName)#

Returns True if Delphi Object is or inherits from ClassName

Read(Buffer, Count: Integer) Integer#

Reads up to Count bytes of data from the resource associated with the handle stream into Buffer. System.Classes.TBufferedFileStream.Read inherits from System.Classes.THandleStream.Read. All content below this line refers to System.Classes.THandleStream.Read. Reads up to Count bytes of data from the resource associated with the handle stream into Buffer. Use Read to read data from the resource associated with the handle stream when the number of bytes in the file is not known. Read transfers up to Count bytes from the resource, starting at the current position, and then advances the current position in the resource by the number of bytes actually transferred. Read returns the number of bytes actually transferred, which may be less than Count if the end of file marker is encountered. All other data-reading methods of a handle stream (ReadBuffer, ReadComponent) call Read to do the actual reading.

ReadBytes()#

Read content as bytes.

ReadFloat()#

Read content as float.

ReadInt()#

Read content as integer.

ReadString()#

Read content as string.

Seek(Offset: Int64, Origin: SeekOrigin) Int64#

Resets the current position of the handle stream. System.Classes.TBufferedFileStream.Seek inherits from System.Classes.THandleStream.Seek. All content below this line refers to System.Classes.THandleStream.Seek. Resets the current position of the handle stream. Use Seek to move the current position within the resource associated with the handle stream by the indicated offset. Seek allows an application to read from or write to a particular location within the resource. The Origin parameter indicates how to interpret the Offset parameter. Origin should be one of the following values:

Value

Meaning

soFromBeginning

Offset is from the beginning of the resource. Seek moves to the position Offset. Offset must be >= 0.

soFromCurrent

Offset is from the current position in the resource. Seek moves to Position + Offset.

soFromEnd

Offset is from the end of the resource. Offset must be <= 0 to indicate a number of bytes before the end of the file.

Or you can also use TSeekOrigin and its values to indicate where to start a seek operation. Seek returns the new value of the Position property, the new current position in the resource.

SetProps(prop1=val1, prop2=val2...)#

Sets several properties in one call

ToList()#

If the object is a container (TStrings, TComponent…), it returns the content of the sequence as a Python list object.

ToTuple()#

If the object is a container (TStrings, TComponent…), it returns the content of the sequence as a Python tuple object.

Write(Buffer, Count: Integer) Integer#

Writes Count bytes from the Buffer to the current position in the resource. System.Classes.TBufferedFileStream.Write inherits from System.Classes.THandleStream.Write. All content below this line refers to System.Classes.THandleStream.Write. Writes Count bytes from the Buffer to the current position in the resource. Use Write to write Count bytes to the resource associated with the handle stream, starting at the current position. After writing to the resource, Write advances the current position by the number bytes written, and returns the number of bytes written. All other data-writing methods of a handle stream (WriteBuffer, WriteComponent) call Write to do the actual writing.

WriteBytes()#

Write content as bytes.

WriteFloat()#

Write content as float.

WriteInt()#

Write content as integer.

WriteString()#

Write content as string.