1- # Stream Functions
1+ # Quorum Stream Functions
22
33[ ![ Latest Stable Version] ( https://poser.pugx.org/quorum/stream-functions/version )] ( https://packagist.org/packages/quorum/stream-functions )
44[ ![ License] ( https://poser.pugx.org/quorum/stream-functions/license )] ( https://packagist.org/packages/quorum/stream-functions )
55[ ![ CI] ( https://github.com/QuorumCollection/StreamFunctions/workflows/CI/badge.svg? )] ( https://github.com/QuorumCollection/StreamFunctions/actions?query=workflow%3ACI )
66
77
8- Useful functions for manipulating PHP streams (resources)
8+ Useful functions for manipulating PHP streams (resources).
9+
10+ The general structure of these are inspired by a [ talk given by Rob Pike] ( https://www.youtube.com/watch?v=HxaD_trXwRE ) .
911
1012## Requirements
1113
@@ -21,20 +23,61 @@ composer require 'quorum/stream-functions'
2123
2224## Stream Functions
2325
24- ### ` Quorum\Streams\faccept( $stream, string ...$accept ) : ?string `
26+ ### Function: \Quorum\Streams\faccept
27+
28+ ``` php
29+ function faccept($stream, string ...$accept) : ?string
30+ ```
31+
32+ ##### Parameters:
2533
26- faccept peeks the given stream for the given string returning it if it is found * or null if it is not.
34+ - *** resource*** ` $stream ` - The stream to peek, must be a seekable resource
35+ - *** string*** ` $accept ` - One or more strings to accept
2736
28- If the string is found, the cursor remains advanced to the end of the string.
37+ ##### Returns:
2938
39+ - *** string*** | *** null*** - The accepted string or null if none were found
40+
41+ faccept peeks the given stream for the given string returning it if it is
42+ found * or null if it is not.
43+
44+ If the string is found, the cursor remains advanced to the end of the string.
3045If the string is not found, the cursor is reset to its original position.
3146
32- ### ` Quorum\Streams\fpeek( $stream, int $length = 1 ) : string `
47+ ### Function: \Quorum\Streams\fpeek
48+
49+ ``` php
50+ function fpeek($stream [, int $length = 1]) : string
51+ ```
52+
53+ ##### Parameters:
3354
34- fpeek peeks the given stream for the given length returning as found.
55+ - *** resource*** ` $stream ` - The stream to peek, must be a seekable resource
56+ - *** int*** ` $length ` - Up to length number of bytes read.
3557
58+ ##### Returns:
59+
60+ - *** string*** - The peeked string of up to length bytes
61+
62+ fpeek peeks the given stream for the given length returning as found.
63+
3664The cursor is reset to its original position.
3765
38- ### ` Quorum\Streams\funtil( $stream, string $until ) : string `
66+ ### Function: \Quorum\Streams\funtil
67+
68+ ``` php
69+ function funtil($stream, string $until [, int $length = 0 [, ?string $buf = null]]) : bool
70+ ```
71+
72+ ##### Parameters:
73+
74+ - *** resource*** ` $stream ` - The stream to read, must be a seekable resource
75+ - *** string*** ` $until ` - The string to read until
76+ - *** int*** ` $length ` - The maximum number of bytes to read, defaults to 0 (no limit)
77+ - *** string*** | *** null*** ` $buf ` - The buffered contents by reference
78+
79+ ##### Returns:
80+
81+ - *** bool***
3982
4083funtil reads the given stream until the given string is found or eof is reached
0 commit comments