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

    var params = [ 'receive' ];
    if (opts.verbose) {
        params.push('-v');
    }

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

    if (opts.force) {
        params.push('-F');
    }

    if (opts.unmounted) {
        params.push('-u');
    }

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

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

    params.push(opts.dataset);

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

        var buffer = [];
        var receiveStream = child.stdin;

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

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

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

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

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

        return cb(null, receiveStream);
    });
}
function receive(opts, cb) {
    "use strict";

    var params = [ 'receive' ];
    if (opts.verbose) {
        params.push('-v');
    }

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

    if (opts.force) {
        params.push('-F');
    }

    if (opts.unmounted) {
        params.push('-u');
    }

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

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

    params.push(opts.dataset);

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

        var buffer = [];
        var receiveStream = child.stdin;

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

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

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

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

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

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

Initiates a receive of a snapshot

Callback is the writable stream

PARAMS:
opts: {
snapshot: string //the location of the snapshot. Follwing structure must be used: pool/project/production@today (must exist)
verbose: boolean //if true, the receiveStream will emit 'verbose' events containing the output of stderr
noop: boolean //if true, zfs will not actually receive anything
force: boolean //if true, dataset will be rolled back to most recent snapshot
unmounted : boolean //if true, dataset will not be mounted after receive
d : boolean //discard first element of received dataset's name
e : boolean //discard all elements except last of received dataset's name
}