Using the PHP Function Stream_Wrapper_Register()
A wrapper is additional code which tells the stream how to handle specific protocols/encodings. For example, the http wrapper knows how to translate a URL into an HTTP/1.0 request for a file on a remote server. There are many wrappers built into PHP by default (See Appendix M), and additional, custom wrappers may be added either within a PHP script using the stream_wrapper_register() function or directly from an extension using the stream_get_wrappers() function.
To create a wrapper class you must implement a number of methods. These will be called by the stream when someone fopens it. The instance of your class will have a context property which will refer to a Context Resource which may be accessed with stream_context_get_options().
fread(stream_wrapper, filehandle, 4096) – 8192 bytes always passed to fread as count, so if you use a larger buffer size than this, fread will return the incorrect amount of data.
dir_opendir() - return first entry in location opened with fopendir()
var:// – read/write access to named global variables using standard filesystem stream functions.
closedir() – closes the directory opened by dir_opendir()
rewinddir() – resets the output generated during rewinddir()
ctrl_read() – returns the current reading position of the stream, used for ftell() and ctrl_write()
ctrl_flush() – flushes the current stream buffer, used for fflush()
ctrl_close() – closes the stream, uses for fclose()
ctrl_return() – return the stream_wrapper object.
ctrl_sync() – synchronizes the read/write position of the stream with its source
ctrl_print() – prints stream contents to stdout.