Exemple #1
0
    }
    if ($end > $len) {
        $end = $len;
    }
    $new = substr($self->raw, $start, $end - $start);
    return new Buffer($new, 'binary');
}, 'toString' => function ($enc = 'utf8', $start = null, $end = null) {
    $self = Func::getContext();
    $raw = $self->raw;
    if (func_num_args() > 1) {
        $raw = substr($raw, $start, $end - $start + 1);
    }
    if ($enc === 'hex') {
        return bin2hex($raw);
    }
    if ($enc === 'base64') {
        return base64_encode($raw);
    }
    return $raw;
}, 'toJSON' => function () {
    $self = Func::getContext();
    return $self->toJSON();
}, 'inspect' => function () {
    $self = Func::getContext();
    return $self->toJSON(Buffer::$SHOW_MAX);
}, 'clone' => function () {
    $self = Func::getContext();
    return new Buffer($self->raw, 'binary');
});
Buffer::$protoObject = new Object();
Buffer::$protoObject->setMethods(Buffer::$protoMethods, true, false, true);