Socket
Socket
Sign inDemoInstall

memcpy

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

2

package.json
{
"name": "memcpy",
"version": "0.2.0",
"version": "0.3.0",
"author": "Daniel Wirtz <dcode@dcode.io>",

@@ -5,0 +5,0 @@ "description": "Copies data between node Buffers and/or ArrayBuffers up to ~75 times faster than in pure JS.",

@@ -30,10 +30,19 @@ node-memcpy

API
---
##### memcpy(target[, targetStart=0], source[, sourceStart=0[, sourceEnd=source.length]):bytesCopied
| Argument | Type | Optional | Description
|--------------|-------------------------|-----------|------------------------------------
| target | Buffer&#124;ArrayBuffer | | Target buffer to copy to
| targetStart | number | omittable | Target offset to begin copying to
| source | Buffer&#124;ArrayBuffer | | Source buffer to copy from
| sourceStart | number | optional | Source offset to begin copying from
| sourceEnd | number | optional | Source offset to end copying from
| **@returns** | number | | Number of bytes copied
Usage
-----
* `npm install memcpy`
* `var memcpy = require("memcpy");`
* `memcpy(target[, targetStart=0], source[, sourceStart=0[, sourceEnd=source.length])`
API
---
```js

@@ -40,0 +49,0 @@ var memcpy = require("memcpy"), // C++ binding if available, else native JS

@@ -54,2 +54,8 @@ /*

/**
* @type {number}
* @inner
*/
var len = 0;
/**
* Copies data between Buffers and/or ArrayBuffers in a uniform way.

@@ -64,2 +70,3 @@ * @exports memcpy

* @param {number=} sourceEnd Source end, defaults to capacity.
* @returns {number} Number of bytes copied
* @throws {Error} If any index is out of bounds

@@ -80,3 +87,4 @@ */

sourceEnd = sourceEnd || source.length;
if (targetStart+sourceEnd-sourceStart > target.length) {
len = sourceEnd - sourceStart;
if (targetStart+len > target.length) {
throw(new Error("Buffer overrun"));

@@ -92,3 +100,4 @@ }

sourceEnd = sourceEnd || source.byteLength;
if (targetStart+sourceEnd-sourceStart > target.length) {
len = sourceEnd - sourceStart;
if (targetStart+len > target.length) {
throw(new Error("Buffer overrun"));

@@ -105,3 +114,4 @@ }

sourceEnd = sourceEnd || source.length;
if (targetStart+sourceEnd-sourceStart > target.byteLength) {
len = sourceEnd - sourceStart;
if (targetStart+len > target.byteLength) {
throw(new Error("Buffer overrun"));

@@ -115,3 +125,4 @@ }

sourceEnd = sourceEnd || source.byteLength;
if (targetStart+sourceEnd-sourceStart > target.byteLength) {
len = sourceEnd-sourceStart;
if (targetStart+len > target.byteLength) {
throw(new Error("Buffer overrun"));

@@ -124,2 +135,3 @@ }

}
return len;
}

@@ -126,0 +138,0 @@

@@ -37,7 +37,7 @@ function fill(buf) {

test.strictEqual(hex(b1), hex(b2));
memcpy(b2, 1, b1, 4, 7);
test.strictEqual(memcpy(b2, 1, b1, 4, 7), 3);
test.strictEqual(hex(b2), "0189ABCD89ABCDEF");
memcpy(b2, b1);
test.strictEqual(memcpy(b2, b1), 8);
test.strictEqual(hex(b2), "0123456789ABCDEF");
memcpy(b2, b1, 4);
test.strictEqual(memcpy(b2, b1, 4), 4);
test.strictEqual(hex(b2), "89ABCDEF89ABCDEF");

@@ -61,12 +61,12 @@ test.throws(function() {

test.strictEqual(hex(b), "0123456789ABCDEF");
memcpy(b, 1, b, 4, 7);
test.strictEqual(memcpy(b, 1, b, 4, 7), 3);
test.strictEqual(hex(b), "0189ABCD89ABCDEF");
fill(b);
memcpy(b, b);
test.strictEqual(memcpy(b, b), 8);
test.strictEqual(hex(b), "0123456789ABCDEF");
fill(b);
memcpy(b, b, 4);
test.strictEqual(memcpy(b, b, 4), 4);
test.strictEqual(hex(b), "89ABCDEF89ABCDEF");
fill(b);
memcpy(b, 4, b, 0, 4);
test.strictEqual(memcpy(b, 4, b, 0, 4), 4);
test.strictEqual(hex(b), "0123456701234567");

@@ -73,0 +73,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc