/** * Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * * @file src/multipart.ts * @author leeight */ /** * Multipart Form Data 编码器 * * 用于创建和编码 multipart/form-data 格式的数据, * 常用于文件上传等场景。 */ export default class Multipart { /** 边界字符串 */ private _boundary; /** 存储所有部分的 Buffer 数组 */ private _parts; /** * 构造函数 * * @param boundary multipart 边界字符串 */ constructor(boundary: string); /** * 添加一个 multipart 部分 * * @param name 字段名称 * @param data 字段数据(字符串或Buffer) * @param contentType 内容类型(可选) * @param filename 文件名(可选,用于文件上传) */ addPart(name: string, data: string | Buffer, contentType?: string, filename?: string): void; /** * 添加文件字段 * * @param name 字段名称 * @param data 文件数据 * @param filename 文件名 * @param contentType 内容类型 */ addFile(name: string, data: Buffer, filename: string, contentType?: string): void; /** * 添加文本字段 * * @param name 字段名称 * @param value 字段值 */ addField(name: string, value: string): void; /** * 编码所有部分为最终的 multipart 数据 * * @returns 编码后的 Buffer */ encode(): Buffer; /** * 获取内容类型头 * * @returns Content-Type 头部值 */ getContentType(): string; /** * 获取边界字符串 * * @returns 边界字符串 */ getBoundary(): string; /** * 获取编码后的数据长度 * * @returns 数据长度(字节) */ getLength(): number; /** * 清空所有部分 */ clear(): void; /** * 获取部分数量 * * @returns 部分数量 */ getPartCount(): number; /** * 生成随机边界字符串 * * @returns 随机边界字符串 */ static generateBoundary(): string; } //# sourceMappingURL=multipart.d.ts.map