| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6202f14 commit b503824
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -961,7 +961,7 @@ A `RangeError` will be thrown if: `targetStart < 0`, `sourceStart < 0`, | |||
| 961 | 961 | added: v0.1.90 | |
| 962 | 962 | --> | |
| 963 | 963 | ||
| 964 | - * `target` {Buffer} A `Buffer` to copy into. | ||
| 964 | + * `target` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`] to copy into. | ||
| 965 | 965 | * `targetStart` {Integer} The offset within `target` at which to begin | |
| 966 | 966 | copying to. **Default:** `0` | |
| 967 | 967 | * `sourceStart` {Integer} The offset within `buf` at which to begin copying from. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,3 +118,29 @@ assert.strictEqual(b.copy(c, 0, 100, 10), 0); | |||
| 118 | 118 | ||
| 119 | 119 | // when targetStart > targetLength, zero copied | |
| 120 | 120 | assert.strictEqual(b.copy(c, 512, 0, 10), 0); | |
| 121 | + | ||
| 122 | + // Test that the `target` can be a Uint8Array. | ||
| 123 | + { | ||
| 124 | + const d = new Uint8Array(c); | ||
| 125 | + // copy 512 bytes, from 0 to 512. | ||
| 126 | + b.fill(++cntr); | ||
| 127 | + d.fill(++cntr); | ||
| 128 | + const copied = b.copy(d, 0, 0, 512); | ||
| 129 | + assert.strictEqual(512, copied); | ||
| 130 | + for (let i = 0; i < d.length; i++) { | ||
| 131 | + assert.strictEqual(b[i], d[i]); | ||
| 132 | + } | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + // Test that the source can be a Uint8Array, too. | ||
| 136 | + { | ||
| 137 | + const e = new Uint8Array(b); | ||
| 138 | + // copy 512 bytes, from 0 to 512. | ||
| 139 | + e.fill(++cntr); | ||
| 140 | + c.fill(++cntr); | ||
| 141 | + const copied = Buffer.prototype.copy.call(e, c, 0, 0, 512); | ||
| 142 | + assert.strictEqual(512, copied); | ||
| 143 | + for (let i = 0; i < c.length; i++) { | ||
| 144 | + assert.strictEqual(e[i], c[i]); | ||
| 145 | + } | ||
| 146 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments