Class yii\mongodb\file\Download
Inheritance | yii\mongodb\file\Download » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable |
Available since version | 2.1 |
Source Code | https://github.com/yiisoft/yii2-mongodb/blob/master/file/Download.php |
Download represents the GridFS download operation.
A Download
object is usually created by calling yii\mongodb\file\Collection::get() or yii\mongodb\file\Collection::createDownload().
Usage example:
Yii::$app->mongodb->getFileCollection()->createDownload($document['_id'])->toFile('/path/to/file.dat');
You can use Download::substr()
to read a specific part of the file:
$filePart = Yii::$app->mongodb->getFileCollection()->createDownload($document['_id'])->substr(256, 1024);
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$collection | yii\mongodb\file\Collection | File collection to be used. | yii\mongodb\file\Download |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\BaseObject |
__construct() | Constructor. | yii\base\BaseObject |
__get() | Returns the value of an object property. | yii\base\BaseObject |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() | Sets value of an object property. | yii\base\BaseObject |
__unset() | Sets an object property to null. | yii\base\BaseObject |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
getBytes() | Alias of toString() method. | yii\mongodb\file\Download |
getChunkCursor() | Returns file chunks read cursor. | yii\mongodb\file\Download |
getChunkIterator() | Returns iterator for the file chunks cursor. | yii\mongodb\file\Download |
getDocument() | yii\mongodb\file\Download | |
getFilename() | Returns associated file's filename. | yii\mongodb\file\Download |
getResource() | Returns persistent stream resource, which can be used to read file. | yii\mongodb\file\Download |
getSize() | Returns the size of the associated file. | yii\mongodb\file\Download |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() | Initializes the object. | yii\base\BaseObject |
setDocument() | Sets data of the document to be downloaded. | yii\mongodb\file\Download |
substr() | Return part of a file. | yii\mongodb\file\Download |
toFile() | Saves download to the physical file. | yii\mongodb\file\Download |
toResource() | Returns an opened stream resource, which can be used to read file. | yii\mongodb\file\Download |
toStream() | Saves file into the given stream. | yii\mongodb\file\Download |
toString() | Returns a string of the bytes in the associated file. | yii\mongodb\file\Download |
write() | Alias of toFile() method. | yii\mongodb\file\Download |
Property Details
File collection to be used.
Method Details
Alias of toString() method.
public string getBytes ( ) | ||
return | string | File content. |
---|
Returns file chunks read cursor.
public \MongoDB\Driver\Cursor getChunkCursor ( $refresh = false ) | ||
$refresh | boolean | Whether to recreate cursor, if it is already exist. |
return | \MongoDB\Driver\Cursor | Chuck list cursor. |
---|---|---|
throws | yii\base\InvalidConfigException |
Returns iterator for the file chunks cursor.
public Iterator getChunkIterator ( $refresh = false ) | ||
$refresh | boolean | Whether to recreate iterator, if it is already exist. |
return | Iterator | Chuck cursor iterator. |
---|
public array getDocument ( ) | ||
return | array | Document to be downloaded. |
---|---|---|
throws | yii\base\InvalidConfigException | on invalid document configuration. |
Returns associated file's filename.
public string|null getFilename ( ) | ||
return | string|null | File name. |
---|
Returns persistent stream resource, which can be used to read file.
public resource getResource ( ) | ||
return | resource | File stream resource. |
---|
Returns the size of the associated file.
public integer getSize ( ) | ||
return | integer | File size. |
---|
Sets data of the document to be downloaded.
Document can be specified by its ID, in this case its data will be fetched automatically via extra query.
public void setDocument ( $document ) | ||
$document | array|\MongoDB\BSON\ObjectID | Document raw data or document ID. |
Return part of a file.
public string|false substr ( $start, $length ) | ||
$start | integer | Reading start position. If non-negative, the returned string will start at the start'th position in file, counting from zero. If negative, the returned string will start at the start'th character from the end of file. |
$length | integer | Number of bytes to read. If given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of file). If given and is negative, then that many characters will be omitted from the end of file (after the start position has been calculated when a start is negative). |
return | string|false | The extracted part of file or |
---|
Saves download to the physical file.
public integer toFile ( $filename ) | ||
$filename | string | Name of the physical file. |
return | integer | Number of written bytes. |
---|
Returns an opened stream resource, which can be used to read file.
Note: each invocation of this method will create new file resource.
public resource toResource ( ) | ||
return | resource | Stream resource. |
---|
Saves file into the given stream.
public integer toStream ( $stream ) | ||
$stream | resource | Stream, which file should be saved to. |
return | integer | Number of written bytes. |
---|
Returns a string of the bytes in the associated file.
public string toString ( ) | ||
return | string | File content. |
---|
Alias of toFile() method.
public integer write ( $filename ) | ||
$filename | string | Name of the physical file. |
return | integer | Number of written bytes. |
---|