File tree 1 file changed +16
-0
lines changed 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -3409,6 +3409,14 @@ console.log(copiedBuf.toString());
3409
3409
3410
3410
console .log (buf .toString ());
3411
3411
// Prints: buffer
3412
+
3413
+ // With buf.slice(), the original buffer is modified.
3414
+ const notReallyCopiedBuf = buf .slice ();
3415
+ notReallyCopiedBuf[0 ]++ ;
3416
+ console .log (notReallyCopiedBuf .toString ());
3417
+ // Prints: cuffer
3418
+ console .log (buf .toString ());
3419
+ // Also prints: cuffer (!)
3412
3420
```
3413
3421
3414
3422
``` cjs
@@ -3423,6 +3431,14 @@ console.log(copiedBuf.toString());
3423
3431
3424
3432
console .log (buf .toString ());
3425
3433
// Prints: buffer
3434
+
3435
+ // With buf.slice(), the original buffer is modified.
3436
+ const notReallyCopiedBuf = buf .slice ();
3437
+ notReallyCopiedBuf[0 ]++ ;
3438
+ console .log (notReallyCopiedBuf .toString ());
3439
+ // Prints: cuffer
3440
+ console .log (buf .toString ());
3441
+ // Also prints: cuffer (!)
3426
3442
```
3427
3443
3428
3444
### ` buf.swap16() `
You can’t perform that action at this time.
0 commit comments