Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

(no description)

File Size: 311 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WritableStream:: (10 methods):
  __construct()
  __debugInfo()
  close()
  getFile()
  getSize()
  tell()
  writeBytes()
  abort()
  fileCollectionInsert()
  insertChunkFromBuffer()


Class: WritableStream  - X-Ref

WritableStream abstracts the process of writing a GridFS file.

__construct(CollectionWrapper $collectionWrapper, string $filename, array $options = [])   X-Ref
Constructs a writable GridFS stream.

Supported options:

* _id (mixed): File document identifier. Defaults to a new ObjectId.

* aliases (array of strings): DEPRECATED An array of aliases.
Applications wishing to store aliases should add an aliases field to
the metadata document instead.

* chunkSizeBytes (integer): The chunk size in bytes. Defaults to
261120 (i.e. 255 KiB).

* disableMD5 (boolean): When true, no MD5 sum will be generated.
Defaults to "false".

* contentType (string): DEPRECATED content type to be stored with the
file. This information should now be added to the metadata.

* metadata (document): User data for the "metadata" field of the files
collection document.

param: CollectionWrapper $collectionWrapper GridFS collection wrapper
param: string            $filename          Filename
param: array             $options           Upload options

__debugInfo()   X-Ref
Return internal properties for debugging purposes.


close()   X-Ref
Closes an active stream and flushes all buffered data to GridFS.


getFile()   X-Ref
Return the stream's file document.


getSize()   X-Ref
Return the stream's size in bytes.

Note: this value will increase as more data is written to the stream.

tell()   X-Ref
Return the current position of the stream.

This is the offset within the stream where the next byte would be
written. Since seeking is not supported and writes are appended, this is
always the end of the stream.


writeBytes(string $data)   X-Ref
Inserts binary data into GridFS via chunks.

Data will be buffered internally until chunkSizeBytes are accumulated, at
which point a chunk document will be inserted and the buffer reset.

param: string $data Binary data to write

abort()   X-Ref
No description

fileCollectionInsert()   X-Ref

return: mixed

insertChunkFromBuffer()   X-Ref
No description