UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

114 lines (113 loc) 3.9 kB
/** * 获取腾讯云COS对象的元数据信息(不返回对象内容) * * @param secretId - 腾讯云API密钥ID * @param secretKey - 腾讯云API密钥Key * @param bucket - COS存储桶名称 * @param region - COS存储桶所在区域 * @param key - 对象键(Object Key),对象在存储桶中的唯一标识 * @returns Promise对象,成功时返回对象的元数据信息(如大小、修改时间等),失败时返回错误信息 * @throws 当参数不全时会抛出错误 * @example * ```typescript * getCosHeadObject({ * secretId: 'your-secret-id', * secretKey: 'your-secret-key', * bucket: 'test-bucket', * region: 'ap-beijing', * key: 'path/to/file.txt' * }) * .then(data => console.log(data)) * .catch(err => console.error(err)); * ``` */ export declare function getCosHeadObject({ secretId, secretKey, bucket, region, key, }: { secretId: string; secretKey: string; bucket: string; region: string; key: string; }): Promise<any>; /** * 下载腾讯云COS对象内容 * * @param secretId - 腾讯云API密钥ID * @param secretKey - 腾讯云API密钥Key * @param bucket - COS存储桶名称 * @param region - COS存储桶所在区域 * @param key - 对象键(Object Key),对象在存储桶中的唯一标识 * @param output - 输出路径或输出流,可选参数。如果指定,对象内容将写入该路径或流 * @returns Promise对象,成功时返回对象内容数据,失败时返回错误信息 * @throws 当参数不全时会抛出错误 * @example * ```typescript * // 下载到内存 * downloadCosObject({ * secretId: 'your-secret-id', * secretKey: 'your-secret-key', * bucket: 'test-bucket', * region: 'ap-beijing', * key: 'path/to/file.txt' * }) * .then(data => console.log(data)) * .catch(err => console.error(err)); * * // 下载到文件 * downloadCosObject({ * secretId: 'your-secret-id', * secretKey: 'your-secret-key', * bucket: 'test-bucket', * region: 'ap-beijing', * key: 'path/to/file.txt', * output: './local/file.txt' * }) * .then(data => console.log('下载成功')) * .catch(err => console.error(err)); * ``` */ export declare function downloadCosObject({ secretId, secretKey, bucket, region, key, output, }: { secretId: string; secretKey: string; bucket: string; region: string; key: string; output?: string | any; }): Promise<any>; /** * 判断 COS 对象与本地文件是否一致(基于 size 与 ETag/MD5) * * 实现说明: * 1. 先比较文件大小(HEAD 返回的 Content-Length 与本地 stat().size);不一致直接判定为不同。 * 2. 大小一致时,再比较 MD5: * - 优先使用 COS 的 `x-cos-meta-md5`(上传时显式设置的元数据,最可靠); * - 否则使用 ETag(仅当对象为简单上传,即 ETag 不含连字符 `-` 时才视为整体 MD5;分块上传 ETag 不可用于直接比较)。 * * @param secretId - 腾讯云 API 密钥 ID * @param secretKey - 腾讯云 API 密钥 Key * @param bucket - COS 存储桶名称 * @param region - COS 存储桶所在区域 * @param key - 对象键 * @param localFilePath - 本地文件路径 * @returns {Promise<boolean>} 一致返回 true,否则 false(本地文件不存在或对象不存在也返回 false) * * @example * ```typescript * const same = await isCosObjectSameAsLocal({ * secretId, secretKey, * bucket: 'test-bucket', region: 'ap-beijing', * key: 'path/to/file.txt', * localFilePath: './local/file.txt', * }); * if (!same) { * // 重新上传 * } * ``` */ export declare function isCosObjectSameAsLocal({ secretId, secretKey, bucket, region, key, localFilePath, }: { secretId: string; secretKey: string; bucket: string; region: string; key: string; localFilePath: string; }): Promise<boolean>;