Skip to content

Commit

Permalink
remove printings
Browse files Browse the repository at this point in the history
Signed-off-by: shirady <[email protected]>
  • Loading branch information
shirady committed Feb 4, 2025
1 parent 32f26c0 commit d7251c3
Showing 1 changed file with 0 additions and 21 deletions.
21 changes: 0 additions & 21 deletions src/util/chunked_content_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@ class ChunkedContentDecoder extends stream.Transform {

/* eslint-disable max-statements */
parse(buf) {
console.log('SDSD JSON.stringify(buf.toString())', JSON.stringify(buf.toString()));
console.log('SDSD buf.length', buf.length);
for (let index = 0; index < buf.length; ++index) {
console.log('SDSD (outer loop) index', index);
if (this.state === STATE_READ_CHUNK_HEADER) {
console.log('SDSD this.state', this.state, 'index', index);
for (; index < buf.length; ++index) {
console.log('SDSD (inner loop) index', index);
if (buf[index] === CR_CODE) {
const header_items = this.chunk_header_str.split(';');
this.chunk_size = parseInt(header_items[0], 16);
Expand All @@ -68,7 +63,6 @@ class ChunkedContentDecoder extends stream.Transform {
const header1 = header_items[1].split('=');
this.chunk_signature = header1[0] === 'chunk-signature' ? header1[1] : '';
}
console.log('SDSD this.chunk_header_str', this.chunk_header_str);
this.chunk_header_str = '';
this.state = STATE_WAIT_NL_HEADER;
break;
Expand All @@ -77,36 +71,27 @@ class ChunkedContentDecoder extends stream.Transform {
}
}
} else if (this.state === STATE_WAIT_NL_HEADER) {
console.log('SDSD this.state', this.state, 'index', index);
if (buf[index] !== NL_CODE) return this.error_state();
this.state = STATE_SEND_DATA;
} else if (this.state === STATE_SEND_DATA) {
console.log('SDSD this.state', this.state, 'index', index);
const content = (index === 0 && buf.length <= this.chunk_size) ? buf : buf.slice(index, index + this.chunk_size);
this.chunk_size -= content.length;
console.log('SDSD index before', index, this.state);
index += content.length - 1;
console.log('SDSD index after', index, this.state);
if (content.length) this.push(content);
if (!this.chunk_size) this.state = STATE_WAIT_TRAILER_DATA;
} else if (this.state === STATE_WAIT_CR_DATA) {
console.log('SDSD this.state', this.state, 'index', index);
if (buf[index] !== CR_CODE) return this.error_state();
this.state = STATE_WAIT_NL_DATA;
} else if (this.state === STATE_WAIT_NL_DATA) {
console.log('SDSD this.state', this.state, 'index', index);
if (buf[index] !== NL_CODE) return this.error_state();
console.log('SDSD this.last_chunk', this.last_chunk);
if (this.last_chunk) {
this.state = STATE_CONTENT_END;
} else {
this.state = STATE_READ_CHUNK_HEADER;
}
} else if (this.state === STATE_WAIT_TRAILER_DATA) {
// TODO - handle trailers (HTTP headers)
console.log('SDSD this.state', this.state, 'index', index);
for (; index < buf.length; ++index) {
console.log('SDSD (new inner loop) index', index);
if (buf[index] === CR_CODE) {
if (buf.length === 2 && buf[index + 1] === NL_CODE) {
this.chunk_trailer_str = '';
Expand All @@ -121,27 +106,21 @@ class ChunkedContentDecoder extends stream.Transform {
}
}
} else if (this.state === STATE_WAIT_CR_TRAILER) {
console.log('SDSD this.state', this.state, 'index', index);
if (buf[index] !== CR_CODE) return this.error_state();
this.state = STATE_WAIT_NL_TRAILER;
} else if (this.state === STATE_WAIT_NL_TRAILER) {
console.log('SDSD this.state', this.state, 'index', index);
if (buf[index] !== NL_CODE) return this.error_state();
this.state = STATE_WAIT_TRAILER_DATA;
} else if (this.state === STATE_WAIT_NL_END) {
console.log('SDSD this.state', this.state, 'index', index);
if (buf[index] !== NL_CODE) return this.error_state();
this.state = STATE_CONTENT_END;
} else {
console.log('SDSD in else condition this.state', this.state);
console.log('SDSD', 'index', index);
return this.error_state();
}
}
}

error_state() {
console.log('SDSD in error_state this.state', this.state);
this.state = STATE_ERROR;
this.emit('error', new Error('problem in parsing aws-chunked data'));
}
Expand Down

0 comments on commit d7251c3

Please sign in to comment.