docs/Writerside/topics/streams.h.md

Fri, 24 Jan 2025 21:12:09 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 24 Jan 2025 21:12:09 +0100
branch
docs/3.1
changeset 1143
0559812df10c
parent 1142
9437530176bc
child 1145
1a8fe7b7dd8a
permissions
-rw-r--r--

assign proper names to the documentation topics

relates to #451

1143
0559812df10c assign proper names to the documentation topics
Mike Becker <universe@uap-core.de>
parents: 1142
diff changeset
1 # Stream Operations
1141
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 UCX provides some utilities for routine tasks.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 The most useful utilities are the *stream copy* functions, which provide a simple way to copy all - or a
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 bounded amount of - data from one stream to another. Since the read/write functions of a UCX buffer are
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 fully compatible with stream read/write functions, you can easily transfer data from file or network streams to
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 a UCX buffer or vice-versa.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 The following example shows, how easy it is to read the contents of a file into a buffer:
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 ```c
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 FILE *inputfile = fopen(infilename, "r");
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 if (inputfile) {
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 CxBuffer fbuf;
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 cxBufferInit(&fbuf, NULL, 4096, NULL, CX_BUFFER_AUTO_EXTEND);
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 cx_stream_copy(inputfile, &fbuf,
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 (cx_read_func) fread,
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 cxBufferWriteFunc);
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 fclose(inputfile);
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 // ... do something meaningful with the contents ...
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 cxBufferDestroy(&fbuf);
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 } else {
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 perror("Error opening input file");
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 if (fout != stdout) {
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 fclose(fout);
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 }
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 }
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 ```
1142
9437530176bc add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents: 1141
diff changeset
31
9437530176bc add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents: 1141
diff changeset
32 ## Undocumented Symbols (TODO)
9437530176bc add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents: 1141
diff changeset
33 ### cx_stream_bncopy
9437530176bc add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents: 1141
diff changeset
34 ### cx_stream_ncopy

mercurial