function testStream()
 {
     $stream = $this->getStream('test1', 'w');
     fwrite($stream, 'foobar');
     fclose($stream);
     $stream = $this->getStream('test1', 'r');
     $data = fread($stream, 6);
     fclose($stream);
     $this->assertEqual('foobar', $data);
     $file = OC::$SERVERROOT . '/3rdparty/MDB2.php';
     $source = fopen($file, 'r');
     $target = $this->getStream('test2', 'w');
     OCP\Files::streamCopy($source, $target);
     fclose($target);
     fclose($source);
     $stream = $this->getStream('test2', 'r');
     $data = stream_get_contents($stream);
     $original = file_get_contents($file);
     $this->assertEqual(strlen($original), strlen($data));
     $this->assertEqual($original, $data);
 }
Beispiel #2
0
 public function testWriteStream()
 {
     $dir = OC::$SERVERROOT . '/tests/data';
     $this->instance = $this->getNew();
     $fh = $this->instance->getStream('lorem.txt', 'w');
     $source = fopen($dir . '/lorem.txt', 'r');
     OCP\Files::streamCopy($source, $fh);
     fclose($source);
     fclose($fh);
     $this->assertTrue($this->instance->fileExists('lorem.txt'));
     $this->assertEquals(file_get_contents($dir . '/lorem.txt'), $this->instance->getFile('lorem.txt'));
 }
Beispiel #3
0
 public function postFopen($path, &$result)
 {
     if (!$result) {
         return $result;
     }
     $meta = stream_get_meta_data($result);
     if (self::isEncrypted($path)) {
         fclose($result);
         $result = fopen('crypt://' . $path, $meta['mode']);
     } elseif (self::shouldEncrypt($path) and $meta['mode'] != 'r' and $meta['mode'] != 'rb') {
         if (OC_Filesystem::file_exists($path) and OC_Filesystem::filesize($path) > 0) {
             //first encrypt the target file so we don't end up with a half encrypted file
             OCP\Util::writeLog('files_encryption', 'Decrypting ' . $path . ' before writing', OCP\Util::DEBUG);
             $tmp = fopen('php://temp');
             OCP\Files::streamCopy($result, $tmp);
             fclose($result);
             OC_Filesystem::file_put_contents($path, $tmp);
             fclose($tmp);
         }
         $result = fopen('crypt://' . $path, $meta['mode']);
     }
     return $result;
 }