index.js 453 B

1234567891011121314151617181920
  1. module.exports = shift
  2. function shift (stream) {
  3. var rs = stream._readableState
  4. if (!rs) return null
  5. return rs.objectMode ? stream.read() : stream.read(getStateLength(rs))
  6. }
  7. function getStateLength (state) {
  8. if (state.buffer.length) {
  9. // Since node 6.3.0 state.buffer is a BufferList not an array
  10. if (state.buffer.head) {
  11. return state.buffer.head.data.length
  12. }
  13. return state.buffer[0].length
  14. }
  15. return state.length
  16. }