@@ -49,7 +49,6 @@ function createFormData(): FormDataBody {
49
49
50
50
function getForm ( pieces : Uint8Array [ ] ) {
51
51
let form : FormDataBody = createFormData ( ) ;
52
- // let form: Form = { fields: {}, files: {} };
53
52
54
53
for ( let piece of pieces ) {
55
54
const { headerByte, contentByte } = splitPiece ( piece ) ;
@@ -60,11 +59,15 @@ function getForm(pieces: Uint8Array[]) {
60
59
// empty content, discard it
61
60
if ( contentByte . byteLength === 1 && contentByte [ 0 ] === 13 ) {
62
61
continue ;
63
- } else {
64
- // headers = "field1"
62
+ }
63
+
64
+ // headers = "field1"
65
+ else {
65
66
form . fields [ headers ] = decoder . decode ( contentByte ) ;
66
67
}
67
- } // it's a file field
68
+ }
69
+
70
+ // it's a file field
68
71
else {
69
72
let file : FormFile = {
70
73
name : headers . name ,
@@ -86,7 +89,9 @@ function getHeaders(headerByte: Uint8Array) {
86
89
// no contentType, it may be a string field, return name only
87
90
if ( contentTypeIndex < 0 ) {
88
91
return getNameOnly ( headerByte ) ;
89
- } // file field, return with name, filename and contentType
92
+ }
93
+
94
+ // file field, return with name, filename and contentType
90
95
else {
91
96
return getHeaderNContentType ( headerByte , contentTypeIndex ) ;
92
97
}
@@ -137,11 +142,13 @@ function getNameNFilename(headerLineByte: Uint8Array, filenameIndex: number) {
137
142
138
143
function getNameOnly ( headerLineByte : Uint8Array ) {
139
144
let nameIndex = bytes . findIndex ( headerLineByte , encode . name ) ;
145
+
140
146
// jump <name="> and get string inside double quote => "string"
141
147
let nameByte = headerLineByte . slice (
142
148
nameIndex + encode . name . byteLength + 2 ,
143
149
headerLineByte . byteLength - 1 ,
144
150
) ;
151
+
145
152
return decoder . decode ( nameByte ) ;
146
153
}
147
154
@@ -166,6 +173,7 @@ function getFieldPieces(
166
173
// jump over boundary + '\r\n'
167
174
buf = buf . slice ( startBoundaryByte . byteLength + 2 ) ;
168
175
let boundaryIndex = bytes . findIndex ( buf , startBoundaryByte ) ;
176
+
169
177
// get field content piece
170
178
pieces . push ( buf . slice ( 0 , boundaryIndex - 1 ) ) ;
171
179
buf = buf . slice ( boundaryIndex ) ;
@@ -177,6 +185,7 @@ function getFieldPieces(
177
185
function getBoundary ( contentType : string ) : Uint8Array | undefined {
178
186
let contentTypeByte = encoder . encode ( contentType ) ;
179
187
let boundaryIndex = bytes . findIndex ( contentTypeByte , encode . boundaryEqual ) ;
188
+
180
189
if ( boundaryIndex >= 0 ) {
181
190
// jump over 'boundary=' to get the real boundary
182
191
let boundary = contentTypeByte . slice (
0 commit comments