| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | module.exports = shift |
| 2 | |
| 3 | function shift (stream) { |
| 4 | var rs = stream._readableState |
| 5 | if (!rs) return null |
| 6 | return (rs.objectMode || typeof stream._duplexState === 'number') ? stream.read() : stream.read(getStateLength(rs)) |
| 7 | } |
| 8 | |
| 9 | function getStateLength (state) { |
| 10 | if (state.buffer.length) { |
| 11 | // Since node 6.3.0 state.buffer is a BufferList not an array |
| 12 | if (state.buffer.head) { |
| 13 | return state.buffer.head.data.length |
| 14 | } |
| 15 | |
| 16 | return state.buffer[0].length |
| 17 | } |
| 18 | |
| 19 | return state.length |
| 20 | } |