MCPcopy
hub / github.com/node-formidable/formidable / _transform

Method _transform

src/parsers/Multipart.js:105–340  ·  view source on GitHub ↗
(buffer, _, done)

Source from the content-addressed store, hash-verified

103
104 // eslint-disable-next-line max-statements
105 _transform(buffer, _, done) {
106 let i = 0;
107 let prevIndex = this.index;
108 let { index, state, flags } = this;
109 const { lookbehind, boundary, boundaryChars } = this;
110 const boundaryLength = boundary.length;
111 const boundaryEnd = boundaryLength - 1;
112 this.bufferLength = buffer.length;
113 let c = null;
114 let cl = null;
115
116 const setMark = (name, idx) => {
117 this[`${name}Mark`] = typeof idx === 'number' ? idx : i;
118 };
119
120 const clearMarkSymbol = (name) => {
121 delete this[`${name}Mark`];
122 };
123
124 const dataCallback = (name, shouldClear) => {
125 const markSymbol = `${name}Mark`;
126 if (!(markSymbol in this)) {
127 return;
128 }
129
130 if (!shouldClear) {
131 this._handleCallback(name, buffer, this[markSymbol], buffer.length);
132 setMark(name, 0);
133 } else {
134 this._handleCallback(name, buffer, this[markSymbol], i);
135 clearMarkSymbol(name);
136 }
137 };
138
139 for (i = 0; i < this.bufferLength; i++) {
140 c = buffer[i];
141 switch (state) {
142 case STATE.PARSER_UNINITIALIZED:
143 done(this._endUnexpected());
144 return;
145 case STATE.START:
146 index = 0;
147 state = STATE.START_BOUNDARY;
148 case STATE.START_BOUNDARY:
149 if (index === boundary.length - 2) {
150 if (c === HYPHEN) {
151 flags |= FBOUNDARY.LAST_BOUNDARY;
152 } else if (c !== CR) {
153 done(this._endUnexpected());
154 return;
155 }
156 index++;
157 break;
158 } else if (index - 1 === boundary.length - 2) {
159 if (flags & FBOUNDARY.LAST_BOUNDARY && c === HYPHEN) {
160 this._handleCallback('end');
161 state = STATE.END;
162 flags = 0;

Callers

nothing calls this directly

Calls 4

_endUnexpectedMethod · 0.95
_handleCallbackMethod · 0.95
doneFunction · 0.85
lowerFunction · 0.85

Tested by

no test coverage detected