/*
创建目录
@param  string  $bucket bucket名称
@param  string  $folder       目录路径
@param  string  $bizAttr    目录属性
486307
public static function createFolder($bucket, $folder, $bizAttr = null) {
        if (!self::isValidPath($folder)) {
            return array(
                        'code' => COSAPI_PARAMS_ERROR,
                        'message' => 'folder ' . $path . ' is not a valid folder name',
                        'data' => array()
                    );
        }

        $folder = self::normalizerPath($folder, True);
        $folder = self::cosUrlEncode($folder);
        $expired = time() + self::EXPIRED_SECONDS;
        $url = self::generateResUrl($bucket, $folder);
        $signature = Auth::createReusableSignature($expired, $bucket);

        $data = array(
            'op' => 'create',
            'biz_attr' => (isset($bizAttr) ? $bizAttr : ''),
        );

        $data = json_encode($data);

        $req = array(
            'url' => $url,
            'method' => 'post',
            'timeout' => self::$timeout,
            'data' => $data,
            'header' => array(
                'Authorization: ' . $signature,
                'Content-Type: application/json',
            ),
        );

        return self::sendRequest($req);
    }
83318
public function rename_folder($folder, $new_name)
    {
        if (!strlen($new_name)) {
            return false;
        }

        if (!$this->check_connection()) {
            return false;
        }

        $delm = $this->get_hierarchy_delimiter();

        // get list of subscribed folders
        if ((strpos($folder, '%') === false) && (strpos($folder, '*') === false)) {
            $a_subscribed = $this->list_folders_subscribed('', $folder . $delm . '*');
            $subscribed   = $this->folder_exists($folder, true);
        }
        else {
            $a_subscribed = $this->list_folders_subscribed();
            $subscribed   = in_array($folder, $a_subscribed);
        }

        $result = $this->conn->renameFolder($folder, $new_name);

        if ($result) {
            // unsubscribe the old folder, subscribe the new one
            if ($subscribed) {
                $this->conn->unsubscribe($folder);
                $this->conn->subscribe($new_name);
            }

            // check if folder children are subscribed
            foreach ($a_subscribed as $c_subscribed) {
                if (strpos($c_subscribed, $folder.$delm) === 0) {
                    $this->conn->unsubscribe($c_subscribed);
                    $this->conn->subscribe(preg_replace('/^'.preg_quote($folder, '/').'/',
                        $new_name, $c_subscribed));

                    // clear cache
                    $this->clear_message_cache($c_subscribed);
                }
            }

            // clear cache
            $this->clear_message_cache($folder);
            $this->clear_cache('mailboxes', true);
        }

        return $result;
    }
460759
public function delete($key, $bucket = '')
    {
        $bucket = $bucket ? $bucket : $this->bucket;
        $encodedEntryURI = self::urlBase64Encode("{$bucket}:{$key}");
        $url = "/delete/{$encodedEntryURI}";
        return $this->fileHandle($url);
    }
985859
public function listFilesOfMemberInFolder($member, $folder, array $filter = null, array $sortOrder = null, array $limit = null) {
		$timeStamp = microtime(true);
		$mModel = $this->kernel->getContainer()->get('membermanagement.model');
		$response = $this->getFileUploadFolder($folder);
		if($response->error->exist){
			return $response;
		}
		$folder = $response->result->set;
		$response = $mModel->getMember($member);
		if($response->error->exist){
			return $response;
		}
		$member = $response->result->set;
		unset($response);
		$filter[] = array(
			'glue' => ' and',
			'condition' => array(
				'column' => $this->entity['f']['alias'] . '.file_upload_folder',
				'comparison' => '=',
				'value' => $folder->getId())
		);
		$response = $this->listFiles($filter, $sortOrder, $limit);

		$response->stats->execution->start = $timeStamp;
		$response->stats->execution->end = microtime(true);

		return $response;
	}
1187513
public static function delFolder($bucket, $folder) {
        if (empty($bucket) || empty($folder)) {
            return array(
                    'code' => COSAPI_PARAMS_ERROR,
                    'message' => 'bucket or path is empty');
        }

        $folder = self::normalizerPath($folder, True);

        return self::delBase($bucket, $folder);
    }
1209218
private static function upload_slice(
        $bucketName, $srcPath, $dstPath,
        $bizAttr = null, $sliceSize = null, $insertOnly = null)
    {
        $srcPath = realpath($srcPath);
        $fileSize = filesize($srcPath);
        $dstPath = self::cosUrlEncode($dstPath);

        $expired = self::time() + self::EXPIRED_SECONDS;
        $url = self::generateResUrl($bucketName, $dstPath);
        $sign = Auth::appSign($expired, $bucketName);
        $sha1 = hash_file('sha1', $srcPath);

        $ret = self::upload_prepare(
                $fileSize, $sha1, $sliceSize,
                $sign, $url, $bizAttr, $insertOnly);

        if ($ret['code'] != 0) {
            return $ret;
        }

        if (isset($ret['data'])
                && isset($ret['data']['url'])) {
            //秒传命中，直接返回了url
            return $ret;
        }

        $sliceSize = $ret['data']['slice_size'];
        if ($sliceSize > self::SLICE_SIZE_3M ||
            $sliceSize <= 0) {
            $ret['code'] = self::COSAPI_PARAMS_ERROR;
            $ret['message'] = 'illegal slice size';

            return $ret;
        }

        $session = $ret['data']['session'];
        $offset = $ret['data']['offset'];

        $sliceCnt = ceil($fileSize / $sliceSize);
        // expired seconds for one slice mutiply by slice count
        // will be the expired seconds for whole file
        $expired = self::time() + (self::EXPIRED_SECONDS * $sliceCnt);
        $sign = Auth::appSign($expired, $bucketName);

        $ret = self::upload_data(
                $fileSize, $sha1, $sliceSize,
                $sign, $url, $srcPath,
                $offset, $session);

        return $ret;
    }
1257061
public Page<Blob> listBlobsWithDirectoryAndPrefix(String bucketName, String directory) {
    // [START listBlobsWithDirectoryAndPrefix]
    Page<Blob> blobs =
        storage.list(
            bucketName, BlobListOption.currentDirectory(), BlobListOption.prefix(directory));
    for (Blob blob : blobs.iterateAll()) {
      // do something with the blob
    }
    // [END listBlobsWithDirectoryAndPrefix]
    return blobs;
  }
1106724
public static function zipDir($sourcePath, $outZipPath, $del = false, $delDir = false)
  {
    $pathInfo = pathInfo($sourcePath);
    $parentPath = $pathInfo['dirname'];
    $dirName = $pathInfo['basename'];

    $z = new \ZipArchive();
    $z->open($outZipPath, \ZipArchive::CREATE);
    $z->addEmptyDir($dirName);
    self::folderToZip($sourcePath, $z, strlen("$parentPath/"), $del);
    if(true===$delDir)rmdir($sourcePath);
    $z->close();
  }
689462
public static function addFolder(&$array, $folder)
    {
        if (is_array($folder)) {
            foreach ($folder as $item) {
                self::addFolder($array, $item);
            }
        } else {
            if (is_dir($folder) && !in_array($folder, $array)) {
                $array[] = $folder;
            }
        }
    }
810156
public static function recursiveUnlink(string $folder, bool $remove_folder = true): bool {

        try {

            self::emptyFolder($folder);
            if ( $remove_folder && rmdir($folder) === false ) {
                throw new Exception("Error deleting folder: $folder");
            }
            return true;

        } catch (Exception $e) {
            throw $e;
        }

    }
1266839
public function dropBucket($bucket)
    {
        $path = "/drop/".$bucket;
        list(, $error) = $this->rsPost($path);
        return $error;
    }
864256
public function transform($folder, array $params = array())
    {
        if (!$folder instanceof FolderInterface) {
            throw new TransformerParameterTypeException();
        }
        $facade = $this->newFacade();
        $facade->folderId = $folder->getId();
        $facade->name = $this->multiLanguageChoiceManager->choose($folder->getNames());
        $facade->createdAt = $folder->getCreatedAt();
        $facade->updatedAt = $folder->getUpdatedAt();
        if ($folder->getParent() instanceof FolderInterface) {
            $facade->parentId = $folder->getParent()->getId();
        } else {
            $facade->parentId = FolderInterface::ROOT_PARENT_ID;
        }
        $facade->siteId = $folder->getSiteId();

        return $facade;
    }
11697
public function mkdirr($folder)
    {
        $folders = preg_split("#[\\\\/]#", $folder);
        $base = '';
        for($i = 0, $c = count($folders); $i < $c; $i++) {
            if(empty($folders[$i])) {
                if (!$i) {
                    // special case for root level
                    $base .= DIRECTORY_SEPARATOR;
                }
                continue;
            }
            $base .= $folders[$i];
            if(!is_dir($base)){
                $this->mkdir($base);
            }
            $base .= DIRECTORY_SEPARATOR;
        }
    }
405120
public static function delFolder($bucketName, $path) {
        $path = self::normalizerPath($path, True);

        return self::delBase($bucketName, $path);
    }
388165
public function setParentFolder(Folder $parent_folder)
    {
        $this->parent_folder = ($this->getId() == 1) ? null : $parent_folder;

        return $this;
    }
677597
public static function statFolder($bucketName, $path) {
        $path = self::normalizerPath($path, True);	

        return self::statBase($bucketName, $path);
    }
1371680
function(bucket) {
    var fs = require('fs');
    var path = require('path');
    var filePath = path.resolve('integ.buckets.json');
    var cache;
    if (fs.existsSync(filePath)) {
      try {
        cache = JSON.parse(fs.readFileSync(filePath));
        cache.buckets.push(bucket);
        fs.writeFileSync(filePath, JSON.stringify(cache));
      } catch (fileErr) {
        throw fileErr;
      }
    } else {
      cache = {};
      cache.buckets = [bucket];
      fs.writeFileSync(filePath, JSON.stringify(cache));
    }
  }