15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Readable, Stream } from 'stream'
 
declare class FormStream extends Stream {
  /**
   * Add a normal field to the form.
   *
   * @param name Name of field
   * @param value Value of field
   */
  field(name: string, value: string, contentType?: string): this
 
  /**
   * Add a local file to be uploaded to the form.
   *
   * @param name Name of file field
   * @param filepath Local path of the file to be uploaded
   * @param filename Name of the file (will be the base name of filepath if empty)
   * @param filesize Size of the file (will not generate Content-Length header if not specified)
   */
  file(
    name: string,
    filepath: string,
    filename?: string,
    filesize?: number,
  ): this
 
  /**
   * Add a buffer as a file to upload.
   *
   * @param name Name of field
   * @param buffer The buffer to be uploaded
   * @param filename The file name that tells the remote server
   * @param contentType Content-Type (aka. MIME Type) of content (will be infered with filename if empty)
   */
  buffer(
    name: string,
    buffer: Buffer,
    filename: string,
    contentType?: string,
  ): this
 
  /**
   * Add a readable stream as a file to upload. Event 'error' will be emitted if an error occured.
   *
   * @param name Name of field
   * @param stream A readable stream to be piped
   * @param filename The file name that tells the remote server
   * @param contentType Content-Type (aka. MIME Type) of content (will be infered with filename if empty)
   * @param size Size of the stream (will not generate Content-Length header if not specified)
   */
  stream(
    name: string,
    stream: Readable,
    filename: string,
    contentType?: string,
    size?: number,
  ): this
 
  /**
   * Get headers for the request.
   *
   * @param additionalHeaders Additional headers
   */
  headers(additionalHeaders?: Record<string, any>): Record<string, any>
}
 
interface FormStreamOptions {
  /** min chunk size to emit data event */
  minChunkSize?: number;
}
 
declare const formStream: {
  new (options?: FormStreamOptions): FormStream
  (options?: FormStreamOptions): FormStream
}
 
interface formStream extends FormStream {}
 
export = formStream