pax_global_header00006660000000000000000000000064127716624520014526gustar00rootroot0000000000000052 comment=7dab09850f080e2d137c62c6a673344fa8458942 clone-buffer-1.0.0/000077500000000000000000000000001277166245200140735ustar00rootroot00000000000000clone-buffer-1.0.0/.editorconfig000066400000000000000000000003051277166245200165460ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false clone-buffer-1.0.0/.eslintrc000066400000000000000000000000301277166245200157100ustar00rootroot00000000000000{ "extends": "gulp" } clone-buffer-1.0.0/.gitignore000066400000000000000000000012541277166245200160650ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Garbage files .DS_Store # Generated by integration tests test/fixtures/tmp test/fixtures/out clone-buffer-1.0.0/.jscsrc000066400000000000000000000000271277166245200153620ustar00rootroot00000000000000{ "preset": "gulp" } clone-buffer-1.0.0/.travis.yml000066400000000000000000000001711277166245200162030ustar00rootroot00000000000000sudo: false language: node_js node_js: - '6' - '5' - '4' - '0.12' - '0.10' after_script: - npm run coveralls clone-buffer-1.0.0/LICENSE000066400000000000000000000022141277166245200150770ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2016 Blaine Bublitz , Eric Schoffstall and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. clone-buffer-1.0.0/README.md000066400000000000000000000027441277166245200153610ustar00rootroot00000000000000

# clone-buffer [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] Easier Buffer cloning in node. ## Example ```js var cloneBuffer = require('clone-buffer'); var buffer = new Buffer('test'); var cloned = cloneBuffer(buffer); // buffer !== cloned ``` ## API ### `cloneBuffer(buffer)` Takes a `Buffer` object and returns a clone. Throws if a non-`Buffer` is passed. ## License MIT [downloads-image]: http://img.shields.io/npm/dm/clone-buffer.svg [npm-url]: https://npmjs.org/package/clone-buffer [npm-image]: http://img.shields.io/npm/v/clone-buffer.svg [travis-url]: https://travis-ci.org/gulpjs/clone-buffer [travis-image]: http://img.shields.io/travis/gulpjs/clone-buffer.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/clone-buffer [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/clone-buffer.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/clone-buffer [coveralls-image]: http://img.shields.io/coveralls/gulpjs/clone-buffer/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.png clone-buffer-1.0.0/appveyor.yml000066400000000000000000000007211277166245200164630ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - nodejs_version: "5" - nodejs_version: "6" install: - ps: Install-Product node $env:nodejs_version - npm install test_script: - node --version - npm --version - cmd: npm test build: off # build version format version: "{build}" clone-buffer-1.0.0/index.js000066400000000000000000000011451277166245200155410ustar00rootroot00000000000000'use strict'; var Buffer = require('buffer').Buffer; function hasFrom() { // Node versions 5.x below 5.10 seem to have a `from` method // However, it doesn't clone Buffers // Luckily, it reports as `false` to hasOwnProperty return (Buffer.hasOwnProperty('from') && typeof Buffer.from === 'function'); } function cloneBuffer(buf) { if (!Buffer.isBuffer(buf)) { throw new Error('Can only clone Buffer.'); } if (hasFrom()) { return Buffer.from(buf); } var copy = new Buffer(buf.length); buf.copy(copy); return copy; } cloneBuffer.hasFrom = hasFrom; module.exports = cloneBuffer; clone-buffer-1.0.0/package.json000066400000000000000000000017471277166245200163720ustar00rootroot00000000000000{ "name": "clone-buffer", "version": "1.0.0", "description": "Easier Buffer cloning in node.", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Blaine Bublitz " ], "repository": "gulpjs/clone-buffer", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "LICENSE", "index.js" ], "scripts": { "lint": "eslint . && jscs index.js test/", "pretest": "npm run lint", "test": "mocha --async-only", "cover": "istanbul cover _mocha --report lcovonly", "coveralls": "npm run cover && istanbul-coveralls" }, "dependencies": {}, "devDependencies": { "eslint": "^1.7.3", "eslint-config-gulp": "^2.0.0", "expect": "^1.19.0", "istanbul": "^0.4.3", "istanbul-coveralls": "^1.0.3", "jscs": "^2.3.5", "jscs-preset-gulp": "^1.0.0", "mocha": "^2.4.5" }, "keywords": [ "buffer", "clone", "from", "copy" ] } clone-buffer-1.0.0/test/000077500000000000000000000000001277166245200150525ustar00rootroot00000000000000clone-buffer-1.0.0/test/.eslintrc000066400000000000000000000000351277166245200166740ustar00rootroot00000000000000{ "extends": "gulp/test" } clone-buffer-1.0.0/test/index.js000066400000000000000000000026151277166245200165230ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var Buffer = require('buffer').Buffer; var cloneBuffer = require('../'); describe('cloneBuffer()', function() { afterEach(function(done) { expect.restoreSpies(); done(); }); it('throws on non-Buffer', function(done) { function invalid() { cloneBuffer('test'); } expect(invalid).toThrow('Can only clone Buffer.'); done(); }); it('uses Buffer.from when available', function(done) { if (!cloneBuffer.hasFrom()) { this.skip(); return; } var fromSpy = expect.spyOn(Buffer, 'from').andCallThrough(); var testBuffer = new Buffer('test'); var cloned = cloneBuffer(testBuffer); expect(cloned).toExist(); expect(fromSpy).toHaveBeenCalled(); done(); }); it('returns a new Buffer reference', function(done) { var testBuffer = new Buffer('test'); var cloned = cloneBuffer(testBuffer); expect(cloned).toExist(); expect(cloned).toBeA(Buffer); expect(cloned).toNotBe(testBuffer); done(); }); it('does not replicate modifications to the original Buffer', function(done) { var testBuffer = new Buffer('test'); var cloned = cloneBuffer(testBuffer); // Test that changes dont modify both pointers cloned.write('w'); expect(testBuffer.toString('utf8')).toEqual('test'); expect(cloned.toString('utf8')).toEqual('west'); done(); }); });