Esempio n. 1
0
function fread(\Nov\CouchDb\Fs\Resource $f, $lenght = null)
{
    if (is_null($lenght)) {
        return $f->raw();
    } else {
        return $f->raw(0, $lenght);
    }
}
Esempio n. 2
0
 function stream_write($data, $lenght = null)
 {
     if (is_null($lenght)) {
         $this->fs->write($data);
     } else {
         $this->fs->write(mb_substr($data, 0, $lenght));
     }
     return strlen($data);
 }
Esempio n. 3
0
 /**
  * @param string $path
  * @param boolean $create 
  * @param boolean $silentMode
  * @return \Nov\CouchDb\Fs\Resource
  */
 public function open($path, $create = false, $silentMode = false)
 {
     if ($create) {
         try {
             $this->_cdb->insert($path, array('dirname' => dirname($path), 'last' => date('c')));
         } catch (\Exception $e) {
             if ($silentMode === false) {
                 throw new Fs\Exception\FileExists('File Exits');
             }
         }
     }
     try {
         $out = $this->_cdb->select($path)->asObject();
     } catch (\Exception $e) {
         throw new Fs\Exception\FileNotFound('FileNotFound');
     }
     if (!isset($out->_attachments)) {
         return Fs\Resource::factory($this->_cdb, $path, null, null);
     } else {
         $attachs = (array) $out->_attachments;
         if (count($attachs) == 0) {
             throw new Fs\Exception('Not found', Fs\Exception\FileNotFound);
         } elseif (count($attachs) > 1) {
             throw new Fs\Exception('System Error', Fs\Exception::SYSTEM_ERROR);
         } else {
             foreach ($attachs as $name => $info) {
             }
             return Fs\Resource::factory($this->_cdb, $path, $name, $info);
         }
     }
 }