@@ -68,16 +68,12 @@ const middy = (lambdaHandler = defaultLambdaHandler, plugin = {}) => {
68
68
if ( handlerBody . _readableState ) {
69
69
handlerStream = handlerBody
70
70
} else if ( typeof handlerBody === 'string' ) {
71
- function * iterator ( input ) {
72
- const size = 16384 // 16 * 1024 // Node.js default
73
- let position = 0
74
- const length = input . length
75
- while ( position <= length ) {
76
- yield input . substring ( position , position + size )
77
- position += size
78
- }
79
- }
80
- handlerStream = Readable . from ( iterator ( handlerBody ) )
71
+ // #1189
72
+ handlerStream = Readable . from (
73
+ handlerBody . length < stringIteratorSize
74
+ ? handlerBody
75
+ : stringIterator ( handlerBody )
76
+ )
81
77
}
82
78
83
79
if ( ! handlerStream ) {
@@ -129,6 +125,16 @@ const middy = (lambdaHandler = defaultLambdaHandler, plugin = {}) => {
129
125
return middy
130
126
}
131
127
128
+ const stringIteratorSize = 16384 // 16 * 1024 // Node.js default
129
+ function * stringIterator ( input ) {
130
+ let position = 0
131
+ const length = input . length
132
+ while ( position < length ) {
133
+ yield input . substring ( position , position + stringIteratorSize )
134
+ position += stringIteratorSize
135
+ }
136
+ }
137
+
132
138
// shared AbortController, because it's slow
133
139
let handlerAbort = new AbortController ( )
134
140
const runRequest = async (
0 commit comments