lib/zfs.js
function send(opts, cb) {
    "use strict";

    var params = [ 'send' ];
    if (opts.replication) {
        params.push('-R');
    }

    if (opts.deduplicate) {
        params.push('-D');
    }

    if (opts.properties) {
        params.push('-p');
    }

    if (opts.noop) {
        params.push('-n');
    }

    if (opts.parsable) {
        params.push('-P');
    }

    if (opts.verbose) {
        params.push('-v');
    }

    if (opts.incremental) {
        if (opts.intermediary) {
            params.push('-I');
        }
        else {
            params.push('-i');
        }

        params.push(opts.incremental);
    }

    params.push(opts.snapshot);

    spawnzfs(params, function (err, child) {
        if (err) {
            return cb(err);
        }

        var buffer = [];
        var sendStream = child.stdout;

        child.stderr.on('data', function (data) {
            data = data.toString();
            buffer.push(data);

            if (opts.verbose) {
                sendStream.emit('verbose', data);
            }

            //only keep last 5 lines
            if (buffer.length > 5) {
                buffer.shift();
            }
        });

        child.once('exit', function (code) {
            if (code !== 0) {
                var message = 'Send Error:' + util.compact(buffer.join('\n').split('\n')).join('; ').trim();
                var err = new Error(message);
                err.code = code;

                sendStream.emit('error', err);
            }
        });

        return cb(null, sendStream);
    });
}
function send(opts, cb) {
    "use strict";

    var params = [ 'send' ];
    if (opts.replication) {
        params.push('-R');
    }

    if (opts.deduplicate) {
        params.push('-D');
    }

    if (opts.properties) {
        params.push('-p');
    }

    if (opts.noop) {
        params.push('-n');
    }

    if (opts.parsable) {
        params.push('-P');
    }

    if (opts.verbose) {
        params.push('-v');
    }

    if (opts.incremental) {
        if (opts.intermediary) {
            params.push('-I');
        }
        else {
            params.push('-i');
        }

        params.push(opts.incremental);
    }

    params.push(opts.snapshot);

    spawnzfs(params, function (err, child) {
        if (err) {
            return cb(err);
        }

        var buffer = [];
        var sendStream = child.stdout;

        child.stderr.on('data', function (data) {
            data = data.toString();
            buffer.push(data);

            if (opts.verbose) {
                sendStream.emit('verbose', data);
            }

            //only keep last 5 lines
            if (buffer.length > 5) {
                buffer.shift();
            }
        });

        child.once('exit', function (code) {
            if (code !== 0) {
                var message = 'Send Error:' + util.compact(buffer.join('\n').split('\n')).join('; ').trim();
                var err = new Error(message);
                err.code = code;

                sendStream.emit('error', err);
            }
        });

        return cb(null, sendStream);
    });
}
/*

Initiates a send operation of a given snapshot

Callback contains a readable stream that is the sendStream
Signature : zfs.send(opts, function (err, sendStream) {});
Events :  sendStream.on('error', function (err) {});
sendStream.on('verbose', function (data) {});

PARAMS:
opts: {
snapshot: string //the location of the snapshot. Follwing structure must be used: pool/project/production@today (must exist)
replication: boolean //create a replication stream
deduplicate: boolean //create a deduplicated stream
properties: boolean //send dataset properties with the stream
noop: boolean //don't actually do anything
parseable : boolean //output in machine readable format
verbose : boolean //emit verbose events containing the contents of stderr
incremental : snapshot //do an incremental send. the snapshot referred to here is the from snapshot
intermediary : boolean //only applies when incremental is set. Include intermediary snapshots with the stream
}