PUT /files/util/native_core.js HTTP/1.1
Host: 127.0.0.1
Accept-Encoding: identity
Content-Length: 776
Content-MD5: 8ovgLxYfYU3ndom4+Aiwng==
Expect: 100-continue
Date: Thu, 08 Dec 2016 13:02:39 GMT
User-Agent: aws-cli/1.11.26 Python/2.7.10 Darwin/16.1.0 botocore/1.4.83
Content-Type: application/javascript
Authorization: AWS 123:I+SouFUd6dyGI1uQWuwhvjcaN3w=

'use strict';

module.exports = lazy_init_native_core;

var _ = require('lodash');
var events = require('events');
var native_core;

function lazy_init_native_core(dont_fail) {
    if (!native_core) {
        try {
            native_core = require('bindings')('native_core.node');

            // see https://github.com/bnoordhuis/node-event-emitter
            inherits(native_core.Nudp, events.EventEmitter);
            inherits(native_core.Ntcp, events.EventEmitter);

        } catch (err) {
            if (!dont_fail) {
                throw err;
            }
        }
    }
    return native_core;
}

// extend prototype
function inherits(target, source) {
    _.forIn(source.prototype, function(v, k) {
        target.prototype[k] = source.prototype[k];
    });
}
