Add a clarifying comment about not coercing buffers passed to read operations.

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2014-06-25 13:51:07 -04:00
parent 25f2a24cdf
commit 76526caa35
1 changed files with 6 additions and 0 deletions

View File

@ -60,6 +60,12 @@ function standard_check_result_cb(callback) {
* Coerce array-like data to Buffer so we can .copy(), etc. * Coerce array-like data to Buffer so we can .copy(), etc.
* Allow null, a Buffer, or an object that can be dealt with * Allow null, a Buffer, or an object that can be dealt with
* by the Buffer constructor (e.g., Typed Array, Array, ...) * by the Buffer constructor (e.g., Typed Array, Array, ...)
*
* WARNING: be very careful not to call this on parameters of
* API methods that pass storage (like read). You don't want to
* overwrite a buffer that a caller is holding a reference to,
* and expects to be filled via the read. If the caller passes
* in a non-Buffer, we should throw instead of coerce.
*/ */
function ensureBuffer(maybeBuffer) { function ensureBuffer(maybeBuffer) {
if(!maybeBuffer) { if(!maybeBuffer) {