summaryrefslogtreecommitdiff
path: root/fpcdocs/bufstream.xml
blob: 6ec9c29851cd4fc224aeaa33d1e88323452e3501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<?xml version="1.0" encoding="ISO-8859-1"?>
<fpdoc-descriptions>
<package name="fcl">

<!--
  ====================================================================
    bufstream
  ====================================================================
-->

<module name="bufstream">
<short>Buffered stream</short>
<descr>
<p>
<file>BufStream</file> implements two one-way buffered streams: the streams
store all data from (or for) the source stream in a memory buffer, and only
flush the buffer when it's full (or refill it when it's empty).
The buffer size can be specified at creation time. 2 streams are
implemented: <link id="TReadBufStream"/> which is for reading only, and
<link id="TWriteBufStream"/> which is for writing only.
</p>
<p>
Buffered streams can help in speeding up read or write operations,
especially when a lot of small read/write operations are done: it 
avoids doing a lot of operating system calls.
</p>
</descr>

<!-- unresolved type reference Visibility: default -->
<element name="Classes">
<short>Stream definitions</short>
</element>

<!-- unresolved type reference Visibility: default -->
<element name="SysUtils">
<short>Exception support</short>
</element>

<!-- constant Visibility: default -->
<element name="DefaultBufferCapacity">
<short>Default buffer size</short>
<descr>
If no buffer size is specified when the stream is created, then this size is
used.
</descr>
<seealso>
<link id="TBufStream.Create"/>
</seealso>
</element>

<!--
  ********************************************************************
    #fcl.bufstream.TBufStream
  ********************************************************************
-->

<!-- object Visibility: default -->
<element name="TBufStream">
<short>Common ancestor for buffered streams</short>
<descr>
<var>TBufStream</var> is the common ancestor for the <link
id="TReadBufStream"/> and <link id="TWriteBufStream"/> streams. 
It completely handles the buffer memory management and position 
management. An instance of <var>TBufStream</var> should never 
be created directly. It also keeps the instance of the source stream.
</descr>
<seealso>
<link id="TReadBufStream"/>
<link id="TWriteBufStream"/>
</seealso>
</element>

<!-- constructor Visibility: public -->
<element name="TBufStream.Create">
<short>Create a new <var>TBufStream</var> instance.</short>
<descr>
<p>
<var>Create</var> creates a new <var>TBufStream</var> instance.
A buffer of size <var>ACapacity</var> is allocated, and the
<var>ASource</var> source (or destination) stream is stored.
If no capacity is specified, then <link id="DefaultBufferCapacity"/> is used
as the capacity.
</p>
<p>
An instance of <var>TBufStream</var> should never be instantiated 
directly. Instead, an instance of <link id="TReadBufStream"/> or
<link id="TWriteBufStream"/> should be created.
</p>
</descr>
<errors>
If not enough memory is available for the buffer, then an exception may be
raised.
</errors>
<seealso>
<link id="TBufStream.Destroy"/>
<link id="TReadBufStream"/>
<link id="TWriteBufStream"/>
</seealso>
</element>

<!-- destructor Visibility: public -->
<element name="TBufStream.Destroy">
<short>Destroys the <var>TBufStream</var> instance</short>
<descr>
<var>Destroy</var> destroys the instance of <var>TBufStream</var>. It
flushes the buffer, deallocates it, and then destroys the
<var>TBufStream</var> instance.
</descr>
<seealso>
<link id="TBufStream.Create"/>
<link id="TReadBufStream"/>
<link id="TWriteBufStream"/>
</seealso>
</element>

<!-- property Visibility: public -->
<element name="TBufStream.Buffer">
<short>The current buffer</short>
<descr>
<var>Buffer</var> is a pointer to the actual buffer in use.
</descr>
<seealso>
<link id="TBufStream.Create"/>
<link id="TBufStream.Capacity"/>
<link id="TBufStream.BufferSize"/>
</seealso>
</element>

<!-- property Visibility: public -->
<element name="TBufStream.Capacity">
<short>Current buffer capacity</short>
<descr>
<var>Capacity</var> is the amount of memory the buffer occupies.
To change the buffer size, the capacity can be set. Note that the
capacity cannot be set to a value that is less than the current
buffer size, i.e. the current amount of data in the buffer.
</descr>
<seealso>
<link id="TBufStream.Create"/>
<link id="TBufStream.Buffer"/>
<link id="TBufStream.BufferSize"/>
<link id="TBufStream.BufferPos"/>
</seealso>
</element>

<!-- property Visibility: public -->
<element name="TBufStream.BufferPos">
<short>Current buffer position.</short>
<descr>
<var>BufPos</var> is the current stream position in the buffer. Depending on
whether the stream is used for reading or writing, data will be read from
this position, or will be written at this position in the buffer.
</descr>
<seealso>
<link id="TBufStream.Create"/>
<link id="TBufStream.Buffer"/>
<link id="TBufStream.BufferSize"/>
<link id="TBufStream.Capacity"/>
</seealso>
</element>

<!-- property Visibility: public -->
<element name="TBufStream.BufferSize">
<short>Amount of data in the buffer</short>
<descr>
<var>BufferSize</var> is the actual amount of data in the buffer. This is
always less than or equal to the <link id="TBufStream.Capacity">Capacity</link>.
</descr>
<seealso>
<link id="TBufStream.Create"/>
<link id="TBufStream.Buffer"/>
<link id="TBufStream.BufferPos"/>
<link id="TBufStream.Capacity"/>
</seealso>
</element>

<!--
  ********************************************************************
    #fcl.bufstream.TReadBufStream
  ********************************************************************
-->

<!-- object Visibility: default -->
<element name="TReadBufStream">
<short>Read-only buffered stream.</short>
<descr>
<p>
<var>TReadBufStream</var> is a read-only buffered stream. It implements the
needed methods to read data from the buffer and fill the buffer with 
additional data when needed.
</p>
<p>
The stream provides limited forward-seek possibilities.
</p>
</descr>
<seealso>
<link id="TBufStream"/>
<link id="TWriteBufStream"/>
</seealso>
</element>

<!-- function Visibility: public -->
<element name="TReadBufStream.Seek">
<short>Set location in the buffer</short>
<descr>
<p>
<var>Seek</var> sets the location in the buffer. Currently, only a forward
seek is allowed. It is emulated by reading and discarding data. For an
explanation of the parameters, see <link id="#rtl.classes.tstream.seek">TStream.Seek"</link>
</p>
<p>
The seek method needs enhancement to enable it to do a full-featured seek.
This may be implemented in a future release of Free Pascal.
</p>
</descr>
<errors>
In case an illegal seek operation is attempted, an exception is raised.
</errors>
<seealso>
<link id="TWriteBufStream.Seek"/>
<link id="TReadBufStream.Read"/>
<link id="TReadBufStream.Write"/>
</seealso>
</element>

<!-- function Visibility: public -->
<element name="TReadBufStream.Read">
<short>Reads data from the stream</short>
<descr>
<p>
<var>Read</var> reads at most <var>ACount</var> bytes from the stream and
places them in <var>Buffer</var>. The number of actually read bytes is
returned.
</p>
<p>
<var>TReadBufStream</var> first reads whatever data is still available in
the buffer, and then refills the buffer, after which it continues to read
data from the buffer. This is repeated untill <var>ACount</var> bytes are
read, or no more data is available.
</p>
</descr>
<seealso>
<link id="TReadBufStream.Seek"/>
<link id="TReadBufStream.Read"/>
</seealso>
</element>

<!-- function Visibility: public -->
<element name="TReadBufStream.Write">
<short>Writes data to the stream</short>
<descr>
<var>Write</var> always raises an <var>EStreamError</var> exception, because
the stream is read-only. A <link id="TWriteBufStream"/> write stream must be
used to write data in a buffered way.
</descr>
<seealso>
<link id="TReadBufStream.Seek"/>
<link id="TReadBufStream.Read"/>
</seealso>
</element>

<!--
  ********************************************************************
    #fcl.bufstream.TWriteBufStream
  ********************************************************************
-->

<!-- object Visibility: default -->
<element name="TWriteBufStream">
<short>Write-only buffered stream.</short>
<descr>
<p>
<var>TWriteBufStream</var> is a write-only buffered stream. It implements the
needed methods to write data to the buffer and flush the buffer (i.e., write
its contents to the source stream) when needed.
</p>
</descr>
<seealso>
<link id="TBufStream"/>
<link id="TReadBufStream"/>
</seealso>
</element>

<!-- destructor Visibility: public -->
<element name="TWriteBufStream.Destroy">
<short>Remove the <var>TWriteBufStream</var> instance from memory</short>
<descr>
<var>Destroy</var> flushes the buffer and then calls the inherited
<link id="TBufstream.Destroy">Destroy</link>.
</descr>
<errors>
If an error occurs during flushing of the buffer, an exception may be
raised.
</errors>
<seealso>
<link id="TBufStream.Create">Create</link>
<link id="TBufStream.Destroy"/>
</seealso>
</element>

<!-- function Visibility: public -->
<element name="TWriteBufStream.Seek">
<short>Set stream position.</short>
<descr>
<p>
<var>Seek</var> always raises an <var>EStreamError</var> exception, 
except when the seek operation would not alter the current position.
</p>
<p>
A later implementation may perform a proper seek operation by flushing the
buffer and doing a seek on the source stream.
</p>
</descr>
<errors>
</errors>
<seealso>
<link id="TWriteBufStream.Write"/>
<link id="TWriteBufStream.Read"/>
<link id="TReadBufStream.Seek"/>
</seealso>
</element>

<!-- function Visibility: public -->
<element name="TWriteBufStream.Read">
<short>Read data from the stream</short>
<descr>
<var>Read</var> always raises an <var>EStreamError</var> 
exception since <var>TWriteBufStream</var> is write-only.
To read data in a buffered way, <link id="TReadBufStream"/> should be used.
</descr>
<seealso>
<link id="TWriteBufStream.Seek"/>
<link id="TWriteBufStream.Write"/>
<link id="TReadBufStream.Read"/>
</seealso>
</element>

<!-- function Visibility: public -->
<element name="TWriteBufStream.Write">
<short>Write data to the stream</short>
<descr>
<var>Write</var> writes at most <var>ACount</var> bytes from
<var>ABuffer</var> to the stream. The data is written to the 
internal buffer first. As soon as the internal buffer is full, it is flushed
to the destination stream, and the internal buffer is filled again. This
process continues till all data is written (or an error occurs).
</descr>
<errors>
An exception may occur if the destination stream has problems writing.
</errors>
<seealso>
<link id="TWriteBufStream.Seek"/>
<link id="TWriteBufStream.Read"/>
<link id="TReadBufStream.Write"/>
</seealso>
</element>


<!-- argument Visibility: default -->
<element name="TBufStream.Create.ASource">
<short>Source stream to buffer data from</short>
</element>

<!-- argument Visibility: default -->
<element name="TBufStream.Create.ACapacity">
<short>Buffer capacity</short>
</element>

<!-- function result Visibility: default -->
<element name="TReadBufStream.Seek.Result">
<short>New position</short>
</element>

<!-- argument Visibility: default -->
<element name="TReadBufStream.Seek.Offset">
<short>Offset (in bytes) of origin</short>
</element>

<!-- argument Visibility: default -->
<element name="TReadBufStream.Seek.Origin">
<short>Origin of seek operation</short>
</element>

<!-- function result Visibility: default -->
<element name="TReadBufStream.Read.Result">
<short>Number of bytes read</short>
</element>

<!-- argument Visibility: default -->
<element name="TReadBufStream.Read.ABuffer">
<short>Buffer to place read data in</short>
</element>

<!-- argument Visibility: default -->
<element name="TReadBufStream.Read.ACount">
<short>Number of bytes to read</short>
</element>

<!-- function result Visibility: default -->
<element name="TReadBufStream.Write.Result">
<short>Number of bytes actually read</short>
</element>

<!-- argument Visibility: default -->
<element name="TReadBufStream.Write.ABuffer">
<short>Buffer containing data to write to stream</short>
</element>

<!-- argument Visibility: default -->
<element name="TReadBufStream.Write.ACount">
<short>Number of bytes to write to stream</short>
</element>

<!-- function result Visibility: default -->
<element name="TWriteBufStream.Seek.Result">
<short>New position</short>
</element>

<!-- argument Visibility: default -->
<element name="TWriteBufStream.Seek.Offset">
<short>Offset (in bytes) of origin</short>
</element>

<!-- argument Visibility: default -->
<element name="TWriteBufStream.Seek.Origin">
<short>Origin of seek operation</short>
</element>

<!-- function result Visibility: default -->
<element name="TWriteBufStream.Read.Result">
<short>Number of bytes read</short>
</element>

<!-- argument Visibility: default -->
<element name="TWriteBufStream.Read.ABuffer">
<short>Buffer to place read bytes in</short>
</element>

<!-- argument Visibility: default -->
<element name="TWriteBufStream.Read.ACount">
<short>Number of bytes to read</short>
</element>

<!-- function result Visibility: default -->
<element name="TWriteBufStream.Write.Result">
<short>Number of bytes written</short>
</element>

<!-- argument Visibility: default -->
<element name="TWriteBufStream.Write.ABuffer">
<short>Buffer containing data to write</short>
</element>

<!-- argument Visibility: default -->
<element name="TWriteBufStream.Write.ACount">
<short>Number of bytes to write to stream</short>
</element>

</module> <!-- bufstream -->

</package>
</fpdoc-descriptions>