webpack-contrib / transform-loader

transform loader for webpack
MIT License
110 stars 23 forks source link

Coerce stream data to a Buffer #11

Closed jgoz closed 9 years ago

jgoz commented 9 years ago

When using Node v4.0.0 and transform-loader, the following error occurs:

buffer.js:219
    buf.copy(buffer, pos);
        ^

TypeError: buf.copy is not a function
    at Function.Buffer.concat (buffer.js:219:9)
    at Stream.<anonymous> (C:\Code\transform-loader\index.js:33:19)
    at emitNone (events.js:72:20)
    at Stream.emit (events.js:166:7)
    at drain (C:\Code\transform-loader\node_modules\brfs\node_modules\through\index.js:33:23)
    at Stream.stream.queue.stream.push (C:\Code\transform-loader\node_modules\brfs\node_modules\through\index.js:41:5)
    at finish (C:\Code\transform-loader\node_modules\brfs\index.js:49:12)
    at C:\Code\transform-loader\node_modules\brfs\index.js:114:38
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

This is reproducible when building test.js in the test folder.

This occurs because Buffer.concat now expects its arguments to be buffers (or to have a copy method), but the data coming back from the stream is usually a string.

The fix is to coerce the data chunks to buffers if needed.

jgoz commented 9 years ago

@sokra Thoughts on this?

sokra commented 9 years ago

Thanks. Sounds good.

jgoz commented 9 years ago

Thanks @sokra. Any chance this can be published to npm?