index.js 607 B

123456789101112131415161718192021
  1. module.exports = shift
  2. function shift (stream) {
  3. var rs = stream._readableState
  4. if (!rs) return null
  5. return (rs.objectMode || typeof stream._duplexState === 'number') ? stream.read() : stream.read(getStateLength(rs))
  6. }
  7. function getStateLength (state) {
  8. if (state.buffer.length) {
  9. var idx = state.bufferIndex || 0
  10. // Since node 6.3.0 state.buffer is a BufferList not an array
  11. if (state.buffer.head) {
  12. return state.buffer.head.data.length
  13. } else if (state.buffer.length - idx > 0 && state.buffer[idx]) {
  14. return state.buffer[idx].length
  15. }
  16. }
  17. return state.length
  18. }