W3cubDocs

/Yii 2.0

Class yii\mongodb\file\Download

Inheritance yii\mongodb\file\Download » yii\base\Object
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
$bytes string File content. yii\mongodb\file\Download
$chunkCursor \MongoDB\Driver\Cursor Chuck list cursor. yii\mongodb\file\Download
$chunkIterator Iterator Chuck cursor iterator. yii\mongodb\file\Download
$collection yii\mongodb\file\Collection File collection to be used. yii\mongodb\file\Download
$document array Document to be downloaded. yii\mongodb\file\Download
$filename string|null File name. yii\mongodb\file\Download
$resource resource File stream resource. yii\mongodb\file\Download
$size integer File size. yii\mongodb\file\Download

Public Methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\Object
__construct() Constructor. yii\base\Object
__get() Returns the value of an object property. yii\base\Object
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Object
__set() Sets value of an object property. yii\base\Object
__unset() Sets an object property to null. yii\base\Object
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Object
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Object
className() Returns the fully qualified name of this class. yii\base\Object
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\Object
hasProperty() Returns a value indicating whether a property is defined. yii\base\Object
init() Initializes the object. yii\base\Object
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

$bytes public read-only property

File content.

public string getBytes ( )

$chunkCursor public read-only property

Chuck list cursor.

public \MongoDB\Driver\Cursor getChunkCursor ( $refresh = false )

$chunkIterator public read-only property

Chuck cursor iterator.

public Iterator getChunkIterator ( $refresh = false )

$collection public property

File collection to be used.

public yii\mongodb\file\Collection $collection = null

$document public property

Document to be downloaded.

public array getDocument ( )
public void setDocument ( $document )

$filename public read-only property

File name.

public string|null getFilename ( )

$resource public read-only property

File stream resource.

public resource getResource ( )

$size public read-only property

File size.

public integer getSize ( )

Method Details

getBytes() public method

Alias of toString() method.

public string getBytes ( )
return string

File content.

getChunkCursor() public method

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

getChunkIterator() public method

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.

getDocument() public method

public array getDocument ( )
return array

Document to be downloaded.

throws yii\base\InvalidConfigException

on invalid document configuration.

getFilename() public method

Returns associated file's filename.

public string|null getFilename ( )
return string|null

File name.

getResource() public method

Returns persistent stream resource, which can be used to read file.

public resource getResource ( )
return resource

File stream resource.

getSize() public method

Returns the size of the associated file.

public integer getSize ( )
return integer

File size.

setDocument() public method

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.

substr() public method

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 false on failure

toFile() public method

Saves download to the physical file.

public integer toFile ( $filename )
$filename string

Name of the physical file.

return integer

Number of written bytes.

toResource() public method

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.

toStream() public method

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.

toString() public method

Returns a string of the bytes in the associated file.

public string toString ( )
return string

File content.

write() public method

Alias of toFile() method.

public integer write ( $filename )
$filename string

Name of the physical file.

return integer

Number of written bytes.

© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-mongodb-file-download.html