This file is indexed.

/usr/share/doc/nodejs/api/buffer.html is in nodejs 4.8.2~dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Buffer | Node.js v4.8.2 Manual &amp; Documentation</title>
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="buffer.html">
</head>
<body class="alt apidoc" id="api-section-buffer">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="Go back to the home page">
          Node.js
        </a>
      </div>
      <ul>
<li><a class="nav-documentation" href="documentation.html">About these Docs</a></li>
<li><a class="nav-synopsis" href="synopsis.html">Usage &amp; Example</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-assert" href="assert.html">Assertion Testing</a></li>
<li><a class="nav-buffer active" href="buffer.html">Buffer</a></li>
<li><a class="nav-addons" href="addons.html">C/C++ Addons</a></li>
<li><a class="nav-child_process" href="child_process.html">Child Processes</a></li>
<li><a class="nav-cluster" href="cluster.html">Cluster</a></li>
<li><a class="nav-cli" href="cli.html">Command Line Options</a></li>
<li><a class="nav-console" href="console.html">Console</a></li>
<li><a class="nav-crypto" href="crypto.html">Crypto</a></li>
<li><a class="nav-debugger" href="debugger.html">Debugger</a></li>
<li><a class="nav-dns" href="dns.html">DNS</a></li>
<li><a class="nav-domain" href="domain.html">Domain</a></li>
<li><a class="nav-errors" href="errors.html">Errors</a></li>
<li><a class="nav-events" href="events.html">Events</a></li>
<li><a class="nav-fs" href="fs.html">File System</a></li>
<li><a class="nav-globals" href="globals.html">Globals</a></li>
<li><a class="nav-http" href="http.html">HTTP</a></li>
<li><a class="nav-https" href="https.html">HTTPS</a></li>
<li><a class="nav-modules" href="modules.html">Modules</a></li>
<li><a class="nav-net" href="net.html">Net</a></li>
<li><a class="nav-os" href="os.html">OS</a></li>
<li><a class="nav-path" href="path.html">Path</a></li>
<li><a class="nav-process" href="process.html">Process</a></li>
<li><a class="nav-punycode" href="punycode.html">Punycode</a></li>
<li><a class="nav-querystring" href="querystring.html">Query Strings</a></li>
<li><a class="nav-readline" href="readline.html">Readline</a></li>
<li><a class="nav-repl" href="repl.html">REPL</a></li>
<li><a class="nav-stream" href="stream.html">Stream</a></li>
<li><a class="nav-string_decoder" href="string_decoder.html">String Decoder</a></li>
<li><a class="nav-timers" href="timers.html">Timers</a></li>
<li><a class="nav-tls" href="tls.html">TLS/SSL</a></li>
<li><a class="nav-tty" href="tty.html">TTY</a></li>
<li><a class="nav-dgram" href="dgram.html">UDP/Datagram</a></li>
<li><a class="nav-url" href="url.html">URL</a></li>
<li><a class="nav-util" href="util.html">Utilities</a></li>
<li><a class="nav-v8" href="v8.html">V8</a></li>
<li><a class="nav-vm" href="vm.html">VM</a></li>
<li><a class="nav-zlib" href="zlib.html">ZLIB</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-https-github-com-nodejs-node" href="https://github.com/nodejs/node">GitHub Repo &amp; Issue Tracker</a></li>
<li><a class="nav-http-groups-google-com-group-nodejs" href="http://groups.google.com/group/nodejs">Mailing List</a></li>
</ul>

    </div>

    <div id="column1" data-id="buffer" class="interior">
      <header>
        <h1>Node.js v4.8.2 Documentation</h1>
        <div id="gtoc">
          <p>
            <a href="index.html" name="toc">Index</a> |
            <a href="all.html">View on single page</a> |
            <a href="buffer.json">View as JSON</a>
          </p>
        </div>
        <hr>
      </header>

      <div id="toc">
        <h2>Table of Contents</h2>
        <ul>
<li><span class="stability_2"><a href="#buffer_buffer">Buffer</a></span><ul>
<li><span class="stability_undefined"><a href="#buffer_buffer_from_buffer_alloc_and_buffer_allocunsafe"><code>Buffer.from()</code>, <code>Buffer.alloc()</code>, and <code>Buffer.allocUnsafe()</code></a></span><ul>
<li><span class="stability_undefined"><a href="#buffer_what_makes_buffer_allocunsafe_size_and_buffer_allocunsafeslow_size_unsafe">What makes <code>Buffer.allocUnsafe(size)</code> and <code>Buffer.allocUnsafeSlow(size)</code> &quot;unsafe&quot;?</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#buffer_buffers_and_character_encodings">Buffers and Character Encodings</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buffers_and_typedarray">Buffers and TypedArray</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buffers_and_es6_iteration">Buffers and ES6 iteration</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_the_zero_fill_buffers_command_line_option">The <code>--zero-fill-buffers</code> command line option</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_buffer">Class: Buffer</a></span><ul>
<li><span class="stability_undefined"><a href="#buffer_new_buffer_array">new Buffer(array)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_new_buffer_buffer">new Buffer(buffer)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_new_buffer_arraybuffer">new Buffer(arrayBuffer)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_new_buffer_size">new Buffer(size)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_new_buffer_str_encoding">new Buffer(str[, encoding])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_alloc_size_fill_encoding">Class Method: Buffer.alloc(size[, fill[, encoding]])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_allocunsafe_size">Class Method: Buffer.allocUnsafe(size)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_allocunsafeslow_size">Class Method: Buffer.allocUnsafeSlow(size)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_bytelength_string_encoding">Class Method: Buffer.byteLength(string[, encoding])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_compare_buf1_buf2">Class Method: Buffer.compare(buf1, buf2)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_concat_list_totallength">Class Method: Buffer.concat(list[, totalLength])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_from_array">Class Method: Buffer.from(array)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_from_arraybuffer">Class Method: Buffer.from(arrayBuffer)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_from_buffer">Class Method: Buffer.from(buffer)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_from_str_encoding">Class Method: Buffer.from(str[, encoding])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_isbuffer_obj">Class Method: Buffer.isBuffer(obj)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_method_buffer_isencoding_encoding">Class Method: Buffer.isEncoding(encoding)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_index">buf[index]</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_compare_otherbuffer">buf.compare(otherBuffer)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_copy_targetbuffer_targetstart_sourcestart_sourceend">buf.copy(targetBuffer[, targetStart[, sourceStart[, sourceEnd]]])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_entries">buf.entries()</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_equals_otherbuffer">buf.equals(otherBuffer)</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_fill_value_offset_end">buf.fill(value[, offset[, end]])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_indexof_value_byteoffset_encoding">buf.indexOf(value[, byteOffset][, encoding])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_keys">buf.keys()</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_length">buf.length</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readdoublebe_offset_noassert">buf.readDoubleBE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readdoublele_offset_noassert">buf.readDoubleLE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readfloatbe_offset_noassert">buf.readFloatBE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readfloatle_offset_noassert">buf.readFloatLE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readint8_offset_noassert">buf.readInt8(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readint16be_offset_noassert">buf.readInt16BE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readint16le_offset_noassert">buf.readInt16LE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readint32be_offset_noassert">buf.readInt32BE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readint32le_offset_noassert">buf.readInt32LE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readintbe_offset_bytelength_noassert">buf.readIntBE(offset, byteLength[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readintle_offset_bytelength_noassert">buf.readIntLE(offset, byteLength[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readuint8_offset_noassert">buf.readUInt8(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readuint16be_offset_noassert">buf.readUInt16BE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readuint16le_offset_noassert">buf.readUInt16LE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readuint32be_offset_noassert">buf.readUInt32BE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readuint32le_offset_noassert">buf.readUInt32LE(offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readuintbe_offset_bytelength_noassert">buf.readUIntBE(offset, byteLength[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_readuintle_offset_bytelength_noassert">buf.readUIntLE(offset, byteLength[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_slice_start_end">buf.slice([start[, end]])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_tostring_encoding_start_end">buf.toString([encoding[, start[, end]]])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_tojson">buf.toJSON()</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_values">buf.values()</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_write_string_offset_length_encoding">buf.write(string[, offset[, length]][, encoding])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writedoublebe_value_offset_noassert">buf.writeDoubleBE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writedoublele_value_offset_noassert">buf.writeDoubleLE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writefloatbe_value_offset_noassert">buf.writeFloatBE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writefloatle_value_offset_noassert">buf.writeFloatLE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeint8_value_offset_noassert">buf.writeInt8(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeint16be_value_offset_noassert">buf.writeInt16BE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeint16le_value_offset_noassert">buf.writeInt16LE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeint32be_value_offset_noassert">buf.writeInt32BE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeint32le_value_offset_noassert">buf.writeInt32LE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeintbe_value_offset_bytelength_noassert">buf.writeIntBE(value, offset, byteLength[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeintle_value_offset_bytelength_noassert">buf.writeIntLE(value, offset, byteLength[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeuint8_value_offset_noassert">buf.writeUInt8(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeuint16be_value_offset_noassert">buf.writeUInt16BE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeuint16le_value_offset_noassert">buf.writeUInt16LE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeuint32be_value_offset_noassert">buf.writeUInt32BE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeuint32le_value_offset_noassert">buf.writeUInt32LE(value, offset[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeuintbe_value_offset_bytelength_noassert">buf.writeUIntBE(value, offset, byteLength[, noAssert])</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_buf_writeuintle_value_offset_bytelength_noassert">buf.writeUIntLE(value, offset, byteLength[, noAssert])</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#buffer_buffer_inspect_max_bytes">buffer.INSPECT_MAX_BYTES</a></span></li>
<li><span class="stability_undefined"><a href="#buffer_class_slowbuffer">Class: SlowBuffer</a></span><ul>
<li><span class="stability_undefined"><a href="#buffer_new_slowbuffer_size">new SlowBuffer(size)</a></span></li>
</ul>
</li>
</ul>
</li>
</ul>

      </div>

      <div id="apicontent">
        <h1>Buffer<span><a class="mark" href="#buffer_buffer" id="buffer_buffer">#</a></span></h1>
<pre class="api_stability api_stability_2">Stability: 2 - Stable</pre><p>Prior to the introduction of <code>TypedArray</code> in ECMAScript 2015 (ES6), the
JavaScript language had no mechanism for reading or manipulating streams
of binary data. The <code>Buffer</code> class was introduced as part of the Node.js
API to make it possible to interact with octet streams in the context of things
like TCP streams and file system operations.</p>
<p>Now that <code>TypedArray</code> has been added in ES6, the <code>Buffer</code> class implements the
<code>Uint8Array</code> API in a manner that is more optimized and suitable for Node.js&#39;
use cases.</p>
<p>Instances of the <code>Buffer</code> class are similar to arrays of integers but
correspond to fixed-sized, raw memory allocations outside the V8 heap.
The size of the <code>Buffer</code> is established when it is created and cannot be
resized.</p>
<p>The <code>Buffer</code> class is a global within Node.js, making it unlikely that one
would need to ever use <code>require(&#39;buffer&#39;).Buffer</code>.</p>
<pre><code class="lang-js">const buf1 = new Buffer(10);
  // creates a buffer of length 10
  // This is the same as Buffer.allocUnsafe(10), and the returned
  // Buffer instance might contain old data that needs to be
  // overwritten using either fill() or write().

const buf2 = new Buffer([1,2,3]);
  // creates a buffer containing [01, 02, 03]
  // This is the same as Buffer.from([1,2,3]).

const buf3 = new Buffer(&#39;test&#39;);
  // creates a buffer containing ASCII bytes [74, 65, 73, 74]
  // This is the same as Buffer.from(&#39;test&#39;).

const buf4 = new Buffer(&#39;tést&#39;, &#39;utf8&#39;);
  // creates a buffer containing UTF8 bytes [74, c3, a9, 73, 74]
  // This is the same as Buffer.from(&#39;tést&#39;, &#39;utf8&#39;).

const buf5 = Buffer.alloc(10);
  // Creates a zero-filled Buffer of length 10.

const buf6 = Buffer.alloc(10, 1);
  // Creates a Buffer of length 10, filled with 0x01.

const buf7 = Buffer.allocUnsafe(10);
  // Creates an uninitialized buffer of length 10.
  // This is faster than calling Buffer.alloc() but the returned
  // Buffer instance might contain old data that needs to be
  // overwritten using either fill() or write().

const buf8 = Buffer.from([1,2,3]);
  // Creates a Buffer containing [01, 02, 03].

const buf9 = Buffer.from(&#39;test&#39;);
  // Creates a Buffer containing ASCII bytes [74, 65, 73, 74].

const buf8 = Buffer.from(&#39;tést&#39;, &#39;utf8&#39;);
  // Creates a Buffer containing UTF8 bytes [74, c3, a9, 73, 74].
</code></pre>
<h2><code>Buffer.from()</code>, <code>Buffer.alloc()</code>, and <code>Buffer.allocUnsafe()</code><span><a class="mark" href="#buffer_buffer_from_buffer_alloc_and_buffer_allocunsafe" id="buffer_buffer_from_buffer_alloc_and_buffer_allocunsafe">#</a></span></h2>
<p>Historically, <code>Buffer</code> instances have been created using the <code>Buffer</code>
constructor function, which allocates the returned <code>Buffer</code>
differently based on what arguments are provided:</p>
<ul>
<li>Passing a number as the first argument to <code>Buffer()</code> (e.g. <code>new Buffer(10)</code>),
allocates a new <code>Buffer</code> object of the specified size. The memory allocated
for such <code>Buffer</code> instances is <em>not</em> initialized and <em>can contain sensitive
data</em>. Such <code>Buffer</code> objects <em>must</em> be initialized <em>manually</em> by using either
<a href="#buffer_buf_fill_value_offset_end"><code>buf.fill(0)</code></a> or by writing to the <code>Buffer</code> completely. While this
behavior is <em>intentional</em> to improve performance, development experience has
demonstrated that a more explicit distinction is required between creating a
fast-but-uninitialized <code>Buffer</code> versus creating a slower-but-safer <code>Buffer</code>.</li>
<li>Passing a string, array, or <code>Buffer</code> as the first argument copies the
passed object&#39;s data into the <code>Buffer</code>.</li>
<li>Passing an <code>ArrayBuffer</code> returns a <code>Buffer</code> that shares allocated memory with
the given <code>ArrayBuffer</code>.</li>
</ul>
<p>Because the behavior of <code>new Buffer()</code> changes significantly based on the type
of value passed as the first argument, applications that do not properly
validate the input arguments passed to <code>new Buffer()</code>, or that fail to
appropriately initialize newly allocated <code>Buffer</code> content, can inadvertently
introduce security and reliability issues into their code.</p>
<p>To make the creation of <code>Buffer</code> objects more reliable and less error prone,
new <code>Buffer.from()</code>, <code>Buffer.alloc()</code>, and <code>Buffer.allocUnsafe()</code> methods have
been introduced as an alternative means of creating <code>Buffer</code> instances.</p>
<p><em>Developers should migrate all existing uses of the <code>new Buffer()</code> constructors
to one of these new APIs.</em></p>
<ul>
<li><a href="#buffer_class_method_buffer_from_array"><code>Buffer.from(array)</code></a> returns a new <code>Buffer</code> containing
a <em>copy</em> of the provided octets.</li>
<li><a href="#buffer_class_method_buffer_from_arraybuffer"><code>Buffer.from(arrayBuffer)</code></a> returns a new <code>Buffer</code>
that <em>shares</em> the same allocated memory as the given <code>ArrayBuffer</code>.</li>
<li><a href="#buffer_class_method_buffer_from_buffer"><code>Buffer.from(buffer)</code></a> returns a new <code>Buffer</code>
containing a <em>copy</em> of the contents of the given <code>Buffer</code>.</li>
<li><a href="#buffer_class_method_buffer_from_str_encoding"><code>Buffer.from(str[, encoding])</code></a> returns a new <code>Buffer</code>
containing a <em>copy</em> of the provided string.</li>
<li><a href="#buffer_class_method_buffer_alloc_size_fill_encoding"><code>Buffer.alloc(size[, fill[, encoding]])</code></a> returns a &quot;filled&quot;
<code>Buffer</code> instance of the specified size. This method can be significantly
slower than <a href="#buffer_class_method_buffer_allocunsafe_size"><code>Buffer.allocUnsafe(size)</code></a> but ensures
that newly created <code>Buffer</code> instances never contain old and potentially
sensitive data.</li>
<li><a href="#buffer_class_method_buffer_allocunsafe_size"><code>Buffer.allocUnsafe(size)</code></a> and
<a href="#buffer_class_method_buffer_allocunsafeslow_size"><code>Buffer.allocUnsafeSlow(size)</code></a> each return a
new <code>Buffer</code> of the specified <code>size</code> whose content <em>must</em> be initialized
using either <a href="#buffer_buf_fill_value_offset_end"><code>buf.fill(0)</code></a> or written to completely.</li>
</ul>
<p><code>Buffer</code> instances returned by <code>Buffer.allocUnsafe(size)</code> <em>may</em> be allocated
off a shared internal memory pool if <code>size</code> is less than or equal to half
<code>Buffer.poolSize</code>. Instances returned by <code>Buffer.allocUnsafeSlow(size)</code> <em>never</em>
use the shared internal memory pool.</p>
<h3>What makes <code>Buffer.allocUnsafe(size)</code> and <code>Buffer.allocUnsafeSlow(size)</code> &quot;unsafe&quot;?<span><a class="mark" href="#buffer_what_makes_buffer_allocunsafe_size_and_buffer_allocunsafeslow_size_unsafe" id="buffer_what_makes_buffer_allocunsafe_size_and_buffer_allocunsafeslow_size_unsafe">#</a></span></h3>
<p>When calling <code>Buffer.allocUnsafe()</code> (and <code>Buffer.allocUnsafeSlow()</code>), the
segment of allocated memory is <em>uninitialized</em> (it is not zeroed-out). While
this design makes the allocation of memory quite fast, the allocated segment of
memory might contain old data that is potentially sensitive. Using a <code>Buffer</code>
created by <code>Buffer.allocUnsafe()</code> without <em>completely</em> overwriting the memory
can allow this old data to be leaked when the <code>Buffer</code> memory is read.</p>
<p>While there are clear performance advantages to using <code>Buffer.allocUnsafe()</code>,
extra care <em>must</em> be taken in order to avoid introducing security
vulnerabilities into an application.</p>
<h2>Buffers and Character Encodings<span><a class="mark" href="#buffer_buffers_and_character_encodings" id="buffer_buffers_and_character_encodings">#</a></span></h2>
<p>Buffers are commonly used to represent sequences of encoded characters
such as UTF8, UCS2, Base64 or even Hex-encoded data. It is possible to
convert back and forth between Buffers and ordinary JavaScript string objects
by using an explicit encoding method.</p>
<pre><code class="lang-js">const buf = new Buffer(&#39;hello world&#39;, &#39;ascii&#39;);
console.log(buf.toString(&#39;hex&#39;));
  // prints: 68656c6c6f20776f726c64
console.log(buf.toString(&#39;base64&#39;));
  // prints: aGVsbG8gd29ybGQ=
</code></pre>
<p>The character encodings currently supported by Node.js include:</p>
<ul>
<li><p><code>&#39;ascii&#39;</code> - for 7-bit ASCII data only.  This encoding method is very fast and
will strip the high bit if set.</p>
</li>
<li><p><code>&#39;utf8&#39;</code> - Multibyte encoded Unicode characters. Many web pages and other
document formats use UTF-8.</p>
</li>
<li><p><code>&#39;utf16le&#39;</code> - 2 or 4 bytes, little-endian encoded Unicode characters.
Surrogate pairs (U+10000 to U+10FFFF) are supported.</p>
</li>
<li><p><code>&#39;ucs2&#39;</code> - Alias of <code>&#39;utf16le&#39;</code>.</p>
</li>
<li><p><code>&#39;base64&#39;</code> - Base64 string encoding. When creating a buffer from a string,
this encoding will also correctly accept &quot;URL and Filename Safe Alphabet&quot; as
specified in <a href="https://tools.ietf.org/html/rfc4648#section-5">RFC 4648, Section 5</a>.</p>
</li>
<li><p><code>&#39;binary&#39;</code> - A way of encoding the buffer into a one-byte (<code>latin-1</code>)
encoded string. The string <code>&#39;latin-1&#39;</code> is not supported. Instead, pass
<code>&#39;binary&#39;</code> to use <code>&#39;latin-1&#39;</code> encoding.</p>
</li>
<li><p><code>&#39;hex&#39;</code> - Encode each byte as two hexadecimal characters.</p>
</li>
</ul>
<h2>Buffers and TypedArray<span><a class="mark" href="#buffer_buffers_and_typedarray" id="buffer_buffers_and_typedarray">#</a></span></h2>
<p>Buffers are also <code>Uint8Array</code> TypedArray instances. However, there are subtle
incompatibilities with the TypedArray specification in ECMAScript 2015. For
instance, while <code>ArrayBuffer#slice()</code> creates a copy of the slice,
the implementation of <a href="#buffer_buf_slice_start_end"><code>Buffer#slice()</code></a> creates a view over the
existing Buffer without copying, making <code>Buffer#slice()</code> far more efficient.</p>
<p>It is also possible to create new TypedArray instances from a <code>Buffer</code> with the
following caveats:</p>
<ol>
<li><p>The Buffer instances&#39;s memory is copied to the TypedArray, not shared.</p>
</li>
<li><p>The Buffer&#39;s memory is interpreted as an array of distinct elements, and not
as a byte array of the target type. That is,
<code>new Uint32Array(new Buffer([1,2,3,4]))</code> creates a 4-element <code>Uint32Array</code>
with elements <code>[1,2,3,4]</code>, not a <code>Uint32Array</code> with a single element
<code>[0x1020304]</code> or <code>[0x4030201]</code>.</p>
</li>
</ol>
<p>It is possible to create a new Buffer that shares the same allocated memory as
a TypedArray instance by using the TypeArray objects <code>.buffer</code> property:</p>
<pre><code class="lang-js">const arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;

const buf1 = new Buffer(arr); // copies the buffer
const buf2 = new Buffer(arr.buffer); // shares the memory with arr;

console.log(buf1);
  // Prints: &lt;Buffer 88 a0&gt;, copied buffer has only two elements
console.log(buf2);
  // Prints: &lt;Buffer 88 13 a0 0f&gt;

arr[1] = 6000;
console.log(buf1);
  // Prints: &lt;Buffer 88 a0&gt;
console.log(buf2);
  // Prints: &lt;Buffer 88 13 70 17&gt;
</code></pre>
<p>Note that when creating a Buffer using the TypeArray&#39;s <code>.buffer</code>, it is not
currently possible to use only a portion of the underlying <code>ArrayBuffer</code>. To
create a Buffer that uses only a part of the <code>ArrayBuffer</code>, use the
<a href="#buffer_buf_slice_start_end"><code>buf.slice()</code></a> function after the Buffer is created:</p>
<pre><code class="lang-js">const arr = new Uint16Array(20);
const buf = new Buffer(arr.buffer).slice(0, 16);
console.log(buf.length);
  // Prints: 16
</code></pre>
<p>The <code>Buffer.from()</code> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from"><code>TypedArray.from()</code></a> (e.g.<code>Uint8Array.from()</code>) have
different signatures and implementations. Specifically, the TypedArray variants
accept a second argument that is a mapping function that is invoked on every
element of the typed array:</p>
<ul>
<li><code>TypedArray.from(source[, mapFn[, thisArg]])</code></li>
</ul>
<p>The <code>Buffer.from()</code> method, however, does not support the use of a mapping
function:</p>
<ul>
<li><a href="#buffer_class_method_buffer_from_array"><code>Buffer.from(array)</code></a></li>
<li><a href="#buffer_class_method_buffer_from_buffer"><code>Buffer.from(buffer)</code></a></li>
<li><a href="#buffer_class_method_buffer_from_arraybuffer"><code>Buffer.from(arrayBuffer)</code></a></li>
<li><a href="#buffer_class_method_buffer_from_str_encoding"><code>Buffer.from(str[, encoding])</code></a></li>
</ul>
<h2>Buffers and ES6 iteration<span><a class="mark" href="#buffer_buffers_and_es6_iteration" id="buffer_buffers_and_es6_iteration">#</a></span></h2>
<p>Buffers can be iterated over using the ECMAScript 2015 (ES6) <code>for..of</code> syntax:</p>
<pre><code class="lang-js">const buf = new Buffer([1, 2, 3]);

for (var b of buf)
  console.log(b)

// Prints:
//   1
//   2
//   3
</code></pre>
<p>Additionally, the <a href="#buffer_buf_values"><code>buf.values()</code></a>, <a href="#buffer_buf_keys"><code>buf.keys()</code></a>, and
<a href="#buffer_buf_entries"><code>buf.entries()</code></a> methods can be used to create iterators.</p>
<h2>The <code>--zero-fill-buffers</code> command line option<span><a class="mark" href="#buffer_the_zero_fill_buffers_command_line_option" id="buffer_the_zero_fill_buffers_command_line_option">#</a></span></h2>
<p>Node.js can be started using the <code>--zero-fill-buffers</code> command line option to
force all newly allocated <code>Buffer</code> and <code>SlowBuffer</code> instances created using
either <code>new Buffer(size)</code> and <code>new SlowBuffer(size)</code> to be <em>automatically
zero-filled</em> upon creation. Use of this flag <em>changes the default behavior</em> of
these methods and <em>can have a significant impact</em> on performance. Use of the
<code>--zero-fill-buffers</code> option is recommended only when absolutely necessary to
enforce that newly allocated <code>Buffer</code> instances cannot contain potentially
sensitive data.</p>
<pre><code>$ node --zero-fill-buffers
&gt; Buffer(5);
&lt;Buffer 00 00 00 00 00&gt;
</code></pre><h2>Class: Buffer<span><a class="mark" href="#buffer_class_buffer" id="buffer_class_buffer">#</a></span></h2>
<p>The Buffer class is a global type for dealing with binary data directly.
It can be constructed in a variety of ways.</p>
<h3>new Buffer(array)<span><a class="mark" href="#buffer_new_buffer_array" id="buffer_new_buffer_array">#</a></span></h3>
<div class="signature"><ul>
<li><code>array</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li>
</ul>
</div><p>Allocates a new Buffer using an <code>array</code> of octets.</p>
<pre><code class="lang-js">const buf = new Buffer([0x62,0x75,0x66,0x66,0x65,0x72]);
  // creates a new Buffer containing ASCII bytes
  // [&#39;b&#39;,&#39;u&#39;,&#39;f&#39;,&#39;f&#39;,&#39;e&#39;,&#39;r&#39;]
</code></pre>
<h3>new Buffer(buffer)<span><a class="mark" href="#buffer_new_buffer_buffer" id="buffer_new_buffer_buffer">#</a></span></h3>
<div class="signature"><ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
</ul>
</div><p>Copies the passed <code>buffer</code> data onto a new <code>Buffer</code> instance.</p>
<pre><code class="lang-js">const buf1 = new Buffer(&#39;buffer&#39;);
const buf2 = new Buffer(buf1);

buf1[0] = 0x61;
console.log(buf1.toString());
  // &#39;auffer&#39;
console.log(buf2.toString());
  // &#39;buffer&#39; (copy is not changed)
</code></pre>
<h3>new Buffer(arrayBuffer)<span><a class="mark" href="#buffer_new_buffer_arraybuffer" id="buffer_new_buffer_arraybuffer">#</a></span></h3>
<div class="signature"><ul>
<li><code>arrayBuffer</code> - The <code>.buffer</code> property of a <code>TypedArray</code> or a <code>new
ArrayBuffer()</code></li>
</ul>
</div><p>When passed a reference to the <code>.buffer</code> property of a <code>TypedArray</code> instance,
the newly created Buffer will share the same allocated memory as the
TypedArray.</p>
<pre><code class="lang-js">const arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;

const buf = new Buffer(arr.buffer); // shares the memory with arr;

console.log(buf);
  // Prints: &lt;Buffer 88 13 a0 0f&gt;

// changing the TypdArray changes the Buffer also
arr[1] = 6000;

console.log(buf);
  // Prints: &lt;Buffer 88 13 70 17&gt;
</code></pre>
<h3>new Buffer(size)<span><a class="mark" href="#buffer_new_buffer_size" id="buffer_new_buffer_size">#</a></span></h3>
<div class="signature"><ul>
<li><code>size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Allocates a new Buffer of <code>size</code> bytes.  The <code>size</code> must be less than
or equal to the value of <code>require(&#39;buffer&#39;).kMaxLength</code> (on 64-bit
architectures, <code>kMaxLength</code> is <code>(2^31)-1</code>). Otherwise, a <a href="errors.html#errors_class_rangeerror"><code>RangeError</code></a> is
thrown. If a <code>size</code> less than 0 is specified, a zero-length Buffer will be
created.</p>
<p>Unlike <code>ArrayBuffers</code>, the underlying memory for Buffer instances created in
this way is not initialized. The contents of a newly created <code>Buffer</code> are
unknown and could contain sensitive data. Use <a href="#buffer_buf_fill_value_offset_end"><code>buf.fill(0)</code></a> to initialize a
Buffer to zeroes.</p>
<pre><code class="lang-js">const buf = new Buffer(5);
console.log(buf);
  // &lt;Buffer 78 e0 82 02 01&gt;
  // (octets will be different, every time)
buf.fill(0);
console.log(buf);
  // &lt;Buffer 00 00 00 00 00&gt;
</code></pre>
<h3>new Buffer(str[, encoding])<span><a class="mark" href="#buffer_new_buffer_str_encoding" id="buffer_new_buffer_str_encoding">#</a></span></h3>
<div class="signature"><ul>
<li><code>str</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> String to encode.</li>
<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> Default: <code>&#39;utf8&#39;</code></li>
</ul>
</div><p>Creates a new Buffer containing the given JavaScript string <code>str</code>. If
provided, the <code>encoding</code> parameter identifies the strings character encoding.</p>
<pre><code class="lang-js">const buf1 = new Buffer(&#39;this is a tést&#39;);
console.log(buf1.toString());
  // prints: this is a tést
console.log(buf1.toString(&#39;ascii&#39;));
  // prints: this is a tC)st

const buf2 = new Buffer(&#39;7468697320697320612074c3a97374&#39;, &#39;hex&#39;);
console.log(buf2.toString());
  // prints: this is a tést
</code></pre>
<h3>Class Method: Buffer.alloc(size[, fill[, encoding]])<span><a class="mark" href="#buffer_class_method_buffer_alloc_size_fill_encoding" id="buffer_class_method_buffer_alloc_size_fill_encoding">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v4.5.0</span>
</div><ul>
<li><code>size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
<li><code>fill</code> <span class="type">&lt;Value&gt;</span> Default: <code>undefined</code></li>
<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> Default: <code>utf8</code></li>
</ul>
<p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>fill</code> is <code>undefined</code>, the
<code>Buffer</code> will be <em>zero-filled</em>.</p>
<pre><code class="lang-js">const buf = Buffer.alloc(5);
console.log(buf);
  // &lt;Buffer 00 00 00 00 00&gt;
</code></pre>
<p>The <code>size</code> must be less than or equal to the value of
<code>require(&#39;buffer&#39;).kMaxLength</code> (on 64-bit architectures, <code>kMaxLength</code> is
<code>(2^31)-1</code>). Otherwise, a <a href="errors.html#errors_class_rangeerror"><code>RangeError</code></a> is thrown. If a <code>size</code> less than 0
is specified, a zero-length <code>Buffer</code> will be created.</p>
<p>If <code>fill</code> is specified, the allocated <code>Buffer</code> will be initialized by calling
<code>buf.fill(fill)</code>. See [<code>buf.fill()</code>][] for more information.</p>
<pre><code class="lang-js">const buf = Buffer.alloc(5, &#39;a&#39;);
console.log(buf);
  // &lt;Buffer 61 61 61 61 61&gt;
</code></pre>
<p>If both <code>fill</code> and <code>encoding</code> are specified, the allocated <code>Buffer</code> will be
initialized by calling <code>buf.fill(fill, encoding)</code>. For example:</p>
<pre><code class="lang-js">const buf = Buffer.alloc(11, &#39;aGVsbG8gd29ybGQ=&#39;, &#39;base64&#39;);
console.log(buf);
  // &lt;Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64&gt;
</code></pre>
<p>Calling <code>Buffer.alloc(size)</code> can be significantly slower than the alternative
<code>Buffer.allocUnsafe(size)</code> but ensures that the newly created <code>Buffer</code> instance
contents will <em>never contain sensitive data</em>.</p>
<p>A <code>TypeError</code> will be thrown if <code>size</code> is not a number.</p>
<h3>Class Method: Buffer.allocUnsafe(size)<span><a class="mark" href="#buffer_class_method_buffer_allocunsafe_size" id="buffer_class_method_buffer_allocunsafe_size">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v4.5.0</span>
</div><ul>
<li><code>size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
<p>Allocates a new <em>non-zero-filled</em> <code>Buffer</code> of <code>size</code> bytes.  The <code>size</code> must
be less than or equal to the value of <code>require(&#39;buffer&#39;).kMaxLength</code> (on 64-bit
architectures, <code>kMaxLength</code> is <code>(2^31)-1</code>). Otherwise, a <a href="errors.html#errors_class_rangeerror"><code>RangeError</code></a> is
thrown. If a <code>size</code> less than 0 is specified, a zero-length <code>Buffer</code> will be
created.</p>
<p>The underlying memory for <code>Buffer</code> instances created in this way is <em>not
initialized</em>. The contents of the newly created <code>Buffer</code> are unknown and
<em>may contain sensitive data</em>. Use <a href="#buffer_buf_fill_value_offset_end"><code>buf.fill(0)</code></a> to initialize such
<code>Buffer</code> instances to zeroes.</p>
<pre><code class="lang-js">const buf = Buffer.allocUnsafe(5);
console.log(buf);
  // &lt;Buffer 78 e0 82 02 01&gt;
  // (octets will be different, every time)
buf.fill(0);
console.log(buf);
  // &lt;Buffer 00 00 00 00 00&gt;
</code></pre>
<p>A <code>TypeError</code> will be thrown if <code>size</code> is not a number.</p>
<p>Note that the <code>Buffer</code> module pre-allocates an internal <code>Buffer</code> instance of
size <code>Buffer.poolSize</code> that is used as a pool for the fast allocation of new
<code>Buffer</code> instances created using <code>Buffer.allocUnsafe(size)</code> (and the
<code>new Buffer(size)</code> constructor) only when <code>size</code> is less than or equal to
<code>Buffer.poolSize &gt;&gt; 1</code> (floor of <code>Buffer.poolSize</code> divided by two). The default
value of <code>Buffer.poolSize</code> is <code>8192</code> but can be modified.</p>
<p>Use of this pre-allocated internal memory pool is a key difference between
calling <code>Buffer.alloc(size, fill)</code> vs. <code>Buffer.allocUnsafe(size).fill(fill)</code>.
Specifically, <code>Buffer.alloc(size, fill)</code> will <em>never</em> use the internal Buffer
pool, while <code>Buffer.allocUnsafe(size).fill(fill)</code> <em>will</em> use the internal
Buffer pool if <code>size</code> is less than or equal to half <code>Buffer.poolSize</code>. The
difference is subtle but can be important when an application requires the
additional performance that <code>Buffer.allocUnsafe(size)</code> provides.</p>
<h3>Class Method: Buffer.allocUnsafeSlow(size)<span><a class="mark" href="#buffer_class_method_buffer_allocunsafeslow_size" id="buffer_class_method_buffer_allocunsafeslow_size">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v4.5.0</span>
</div><ul>
<li><code>size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
<p>Allocates a new <em>non-zero-filled</em> and non-pooled <code>Buffer</code> of <code>size</code> bytes.  The
<code>size</code> must be less than or equal to the value of
<code>require(&#39;buffer&#39;).kMaxLength</code> (on 64-bit architectures, <code>kMaxLength</code> is
<code>(2^31)-1</code>). Otherwise, a <a href="errors.html#errors_class_rangeerror"><code>RangeError</code></a> is thrown. If a <code>size</code> less than 0
is specified, a zero-length <code>Buffer</code> will be created.</p>
<p>The underlying memory for <code>Buffer</code> instances created in this way is <em>not
initialized</em>. The contents of the newly created <code>Buffer</code> are unknown and
<em>may contain sensitive data</em>. Use <a href="#buffer_buf_fill_value_offset_end"><code>buf.fill(0)</code></a> to initialize such
<code>Buffer</code> instances to zeroes.</p>
<p>When using <code>Buffer.allocUnsafe()</code> to allocate new <code>Buffer</code> instances,
allocations under 4KB are, by default, sliced from a single pre-allocated
<code>Buffer</code>. This allows applications to avoid the garbage collection overhead of
creating many individually allocated Buffers. This approach improves both
performance and memory usage by eliminating the need to track and cleanup as
many <code>Persistent</code> objects.</p>
<p>However, in the case where a developer may need to retain a small chunk of
memory from a pool for an indeterminate amount of time, it may be appropriate
to create an un-pooled Buffer instance using <code>Buffer.allocUnsafeSlow()</code> then
copy out the relevant bits.</p>
<pre><code class="lang-js">// need to keep around a few small chunks of memory
const store = [];

socket.on(&#39;readable&#39;, () =&gt; {
  const data = socket.read();
  // allocate for retained data
  const sb = Buffer.allocUnsafeSlow(10);
  // copy the data into the new allocation
  data.copy(sb, 0, 0, 10);
  store.push(sb);
});
</code></pre>
<p>Use of <code>Buffer.allocUnsafeSlow()</code> should be used only as a last resort <em>after</em>
a developer has observed undue memory retention in their applications.</p>
<p>A <code>TypeError</code> will be thrown if <code>size</code> is not a number.</p>
<h3>Class Method: Buffer.byteLength(string[, encoding])<span><a class="mark" href="#buffer_class_method_buffer_bytelength_string_encoding" id="buffer_class_method_buffer_bytelength_string_encoding">#</a></span></h3>
<div class="signature"><ul>
<li><code>string</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a></li>
<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> Default: <code>&#39;utf8&#39;</code></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Returns the actual byte length of a string. This is not the same as
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length"><code>String.prototype.length</code></a> since that returns the number of <em>characters</em> in
a string.</p>
<p><em>Note</em> that for <code>&#39;base64&#39;</code> and <code>&#39;hex&#39;</code>, this function assumes valid input. For
strings that contain non-Base64/Hex-encoded data (e.g. whitespace), the return
value might be greater than the length of a <code>Buffer</code> created from the string.</p>
<p>Example:</p>
<pre><code class="lang-js">const str = &#39;\u00bd + \u00bc = \u00be&#39;;

console.log(`${str}: ${str.length} characters, ` +
            `${Buffer.byteLength(str, &#39;utf8&#39;)} bytes`);

// ½ + ¼ = ¾: 9 characters, 12 bytes
</code></pre>
<h3>Class Method: Buffer.compare(buf1, buf2)<span><a class="mark" href="#buffer_class_method_buffer_compare_buf1_buf2" id="buffer_class_method_buffer_compare_buf1_buf2">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.11.13</span>
</div><ul>
<li><code>buf1</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
<li><code>buf2</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
<p>Compares <code>buf1</code> to <code>buf2</code> typically for the purpose of sorting arrays of
Buffers. This is equivalent is calling <a href="#buffer_buf_compare_otherbuffer"><code>buf1.compare(buf2)</code></a>.</p>
<pre><code class="lang-js">const arr = [Buffer(&#39;1234&#39;), Buffer(&#39;0123&#39;)];
arr.sort(Buffer.compare);
</code></pre>
<h3>Class Method: Buffer.concat(list[, totalLength])<span><a class="mark" href="#buffer_class_method_buffer_concat_list_totallength" id="buffer_class_method_buffer_concat_list_totallength">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.7.11</span>
</div><ul>
<li><code>list</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a> List of Buffer objects to concat</li>
<li><code>totalLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Total length of the Buffers in the list when concatenated</li>
<li>Returns: <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
</ul>
<p>Returns a new Buffer which is the result of concatenating all the Buffers in
the <code>list</code> together.</p>
<p>If the list has no items, or if the <code>totalLength</code> is 0, then a new zero-length
Buffer is returned.</p>
<p>If <code>totalLength</code> is not provided, it is calculated from the Buffers in the
<code>list</code>. This, however, adds an additional loop to the function, so it is faster
to provide the length explicitly.</p>
<p>Example: build a single Buffer from a list of three Buffers:</p>
<pre><code class="lang-js">const buf1 = new Buffer(10).fill(0);
const buf2 = new Buffer(14).fill(0);
const buf3 = new Buffer(18).fill(0);
const totalLength = buf1.length + buf2.length + buf3.length;

console.log(totalLength);
const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
console.log(bufA);
console.log(bufA.length);

// 42
// &lt;Buffer 00 00 00 00 ...&gt;
// 42
</code></pre>
<h3>Class Method: Buffer.from(array)<span><a class="mark" href="#buffer_class_method_buffer_from_array" id="buffer_class_method_buffer_from_array">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v4.5.0</span>
</div><ul>
<li><code>array</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li>
</ul>
<p>Allocates a new <code>Buffer</code> using an <code>array</code> of octets.</p>
<pre><code class="lang-js">const buf = Buffer.from([0x62,0x75,0x66,0x66,0x65,0x72]);
  // creates a new Buffer containing ASCII bytes
  // [&#39;b&#39;,&#39;u&#39;,&#39;f&#39;,&#39;f&#39;,&#39;e&#39;,&#39;r&#39;]
</code></pre>
<p>A <code>TypeError</code> will be thrown if <code>array</code> is not an <code>Array</code>.</p>
<h3>Class Method: Buffer.from(arrayBuffer)<span><a class="mark" href="#buffer_class_method_buffer_from_arraybuffer" id="buffer_class_method_buffer_from_arraybuffer">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v4.5.0</span>
</div><ul>
<li><code>arrayBuffer</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&lt;ArrayBuffer&gt;</a> The <code>.buffer</code> property of a <code>TypedArray</code> or
a <code>new ArrayBuffer()</code></li>
</ul>
<p>When passed a reference to the <code>.buffer</code> property of a <code>TypedArray</code> instance,
the newly created <code>Buffer</code> will share the same allocated memory as the
TypedArray.</p>
<pre><code class="lang-js">const arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;

const buf = Buffer.from(arr.buffer); // shares the memory with arr;

console.log(buf);
  // Prints: &lt;Buffer 88 13 a0 0f&gt;

// changing the TypedArray changes the Buffer also
arr[1] = 6000;

console.log(buf);
  // Prints: &lt;Buffer 88 13 70 17&gt;
</code></pre>
<p>A <code>TypeError</code> will be thrown if <code>arrayBuffer</code> is not an <code>ArrayBuffer</code>.</p>
<h3>Class Method: Buffer.from(buffer)<span><a class="mark" href="#buffer_class_method_buffer_from_buffer" id="buffer_class_method_buffer_from_buffer">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v4.5.0</span>
</div><ul>
<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
</ul>
<p>Copies the passed <code>buffer</code> data onto a new <code>Buffer</code> instance.</p>
<pre><code class="lang-js">const buf1 = Buffer.from(&#39;buffer&#39;);
const buf2 = Buffer.from(buf1);

buf1[0] = 0x61;
console.log(buf1.toString());
  // &#39;auffer&#39;
console.log(buf2.toString());
  // &#39;buffer&#39; (copy is not changed)
</code></pre>
<p>A <code>TypeError</code> will be thrown if <code>buffer</code> is not a <code>Buffer</code>.</p>
<h3>Class Method: Buffer.from(str[, encoding])<span><a class="mark" href="#buffer_class_method_buffer_from_str_encoding" id="buffer_class_method_buffer_from_str_encoding">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v4.5.0</span>
</div><ul>
<li><code>str</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> String to encode.</li>
<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> Encoding to use, Default: <code>&#39;utf8&#39;</code></li>
</ul>
<p>Creates a new <code>Buffer</code> containing the given JavaScript string <code>str</code>. If
provided, the <code>encoding</code> parameter identifies the character encoding.
If not provided, <code>encoding</code> defaults to <code>&#39;utf8&#39;</code>.</p>
<pre><code class="lang-js">const buf1 = Buffer.from(&#39;this is a tést&#39;);
console.log(buf1.toString());
  // prints: this is a tést
console.log(buf1.toString(&#39;ascii&#39;));
  // prints: this is a tC)st

const buf2 = Buffer.from(&#39;7468697320697320612074c3a97374&#39;, &#39;hex&#39;);
console.log(buf2.toString());
  // prints: this is a tést
</code></pre>
<p>A <code>TypeError</code> will be thrown if <code>str</code> is not a string.</p>
<h3>Class Method: Buffer.isBuffer(obj)<span><a class="mark" href="#buffer_class_method_buffer_isbuffer_obj" id="buffer_class_method_buffer_isbuffer_obj">#</a></span></h3>
<div class="signature"><ul>
<li><code>obj</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a></li>
</ul>
</div><p>Returns &#39;true&#39; if <code>obj</code> is a Buffer.</p>
<h3>Class Method: Buffer.isEncoding(encoding)<span><a class="mark" href="#buffer_class_method_buffer_isencoding_encoding" id="buffer_class_method_buffer_isencoding_encoding">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.9.1</span>
</div><ul>
<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> The encoding string to test</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a></li>
</ul>
<p>Returns true if the <code>encoding</code> is a valid encoding argument, or false
otherwise.</p>
<h3>buf[index]<span><a class="mark" href="#buffer_buf_index" id="buffer_buf_index">#</a></span></h3>
<div class="api_metadata">
</div><p>The index operator <code>[index]</code> can be used to get and set the octet at position
<code>index</code> in the Buffer. The values refer to individual bytes, so the legal value
range is between <code>0x00</code> and <code>0xFF</code> (hex) or <code>0</code> and <code>255</code> (decimal).</p>
<p>Example: copy an ASCII string into a Buffer, one byte at a time:</p>
<pre><code class="lang-js">const str = &quot;Node.js&quot;;
const buf = new Buffer(str.length);

for (var i = 0; i &lt; str.length ; i++) {
  buf[i] = str.charCodeAt(i);
}

console.log(buf.toString(&#39;ascii&#39;));
  // Prints: Node.js
</code></pre>
<h3>buf.compare(otherBuffer)<span><a class="mark" href="#buffer_buf_compare_otherbuffer" id="buffer_buf_compare_otherbuffer">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.11.13</span>
</div><ul>
<li><code>otherBuffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
<p>Compares two Buffer instances and returns a number indicating whether <code>buf</code>
comes before, after, or is the same as the <code>otherBuffer</code> in sort order.
Comparison is based on the actual sequence of bytes in each Buffer.</p>
<ul>
<li><code>0</code> is returned if <code>otherBuffer</code> is the same as <code>buf</code></li>
<li><code>1</code> is returned if <code>otherBuffer</code> should come <em>before</em> <code>buf</code> when sorted.</li>
<li><code>-1</code> is returned if <code>otherBuffer</code> should come <em>after</em> <code>buf</code> when sorted.</li>
</ul>
<pre><code class="lang-js">const buf1 = new Buffer(&#39;ABC&#39;);
const buf2 = new Buffer(&#39;BCD&#39;);
const buf3 = new Buffer(&#39;ABCD&#39;);

console.log(buf1.compare(buf1));
  // Prints: 0
console.log(buf1.compare(buf2));
  // Prints: -1
console.log(buf1.compare(buf3));
  // Prints: -1
console.log(buf2.compare(buf1));
  // Prints: 1
console.log(buf2.compare(buf3));
  // Prints: 1

[buf1, buf2, buf3].sort(Buffer.compare);
  // produces sort order [buf1, buf3, buf2]
</code></pre>
<h3>buf.copy(targetBuffer[, targetStart[, sourceStart[, sourceEnd]]])<span><a class="mark" href="#buffer_buf_copy_targetbuffer_targetstart_sourcestart_sourceend" id="buffer_buf_copy_targetbuffer_targetstart_sourcestart_sourceend">#</a></span></h3>
<div class="signature"><ul>
<li><code>targetBuffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> Buffer to copy into</li>
<li><code>targetStart</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: 0</li>
<li><code>sourceStart</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: 0</li>
<li><code>sourceEnd</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: <code>buffer.length</code></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The number of bytes copied.</li>
</ul>
</div><p>Copies data from a region of this Buffer to a region in the target Buffer even
if the target memory region overlaps with the source.</p>
<p>Example: build two Buffers, then copy <code>buf1</code> from byte 16 through byte 19
into <code>buf2</code>, starting at the 8th byte in <code>buf2</code>.</p>
<pre><code class="lang-js">const buf1 = new Buffer(26);
const buf2 = new Buffer(26).fill(&#39;!&#39;);

for (var i = 0 ; i &lt; 26 ; i++) {
  buf1[i] = i + 97; // 97 is ASCII a
}

buf1.copy(buf2, 8, 16, 20);
console.log(buf2.toString(&#39;ascii&#39;, 0, 25));
  // Prints: !!!!!!!!qrst!!!!!!!!!!!!!
</code></pre>
<p>Example: Build a single Buffer, then copy data from one region to an overlapping
region in the same Buffer</p>
<pre><code class="lang-js">const buf = new Buffer(26);

for (var i = 0 ; i &lt; 26 ; i++) {
  buf[i] = i + 97; // 97 is ASCII a
}

buf.copy(buf, 0, 4, 10);
console.log(buf.toString());

// efghijghijklmnopqrstuvwxyz
</code></pre>
<h3>buf.entries()<span><a class="mark" href="#buffer_buf_entries" id="buffer_buf_entries">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v1.1.0</span>
</div><ul>
<li>Returns: <span class="type">&lt;Iterator&gt;</span></li>
</ul>
<p>Creates and returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols">iterator</a> of <code>[index, byte]</code> pairs from the Buffer
contents.</p>
<pre><code class="lang-js">const buf = new Buffer(&#39;buffer&#39;);
for (var pair of buf.entries()) {
  console.log(pair);
}
// prints:
//   [0, 98]
//   [1, 117]
//   [2, 102]
//   [3, 102]
//   [4, 101]
//   [5, 114]
</code></pre>
<h3>buf.equals(otherBuffer)<span><a class="mark" href="#buffer_buf_equals_otherbuffer" id="buffer_buf_equals_otherbuffer">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v1.0.0</span>
</div><ul>
<li><code>otherBuffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a></li>
</ul>
<p>Returns a boolean indicating whether <code>this</code> and <code>otherBuffer</code> have exactly the
same bytes.</p>
<pre><code class="lang-js">const buf1 = new Buffer(&#39;ABC&#39;);
const buf2 = new Buffer(&#39;414243&#39;, &#39;hex&#39;);
const buf3 = new Buffer(&#39;ABCD&#39;);

console.log(buf1.equals(buf2));
  // Prints: true
console.log(buf1.equals(buf3));
  // Prints: false
</code></pre>
<h3>buf.fill(value[, offset[, end]])<span><a class="mark" href="#buffer_buf_fill_value_offset_end" id="buffer_buf_fill_value_offset_end">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.5.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: 0</li>
<li><code>end</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: <code>buffer.length</code></li>
<li>Returns: <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
</ul>
<p>Fills the Buffer with the specified value. If the <code>offset</code> and <code>end</code> are not
given it will fill the entire Buffer. The method returns a reference to the
Buffer so calls can be chained.</p>
<pre><code class="lang-js">const b = new Buffer(50).fill(&#39;h&#39;);
console.log(b.toString());
  // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
</code></pre>
<h3>buf.indexOf(value[, byteOffset][, encoding])<span><a class="mark" href="#buffer_buf_indexof_value_byteoffset_encoding" id="buffer_buf_indexof_value_byteoffset_encoding">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v1.5.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> | <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
<li><code>byteOffset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: 0</li>
<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> Default: <code>&#39;utf8&#39;</code></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
<p>Operates similar to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf"><code>Array#indexOf()</code></a> in that it returns either the
starting index position of <code>value</code> in Buffer or <code>-1</code> if the Buffer does not
contain <code>value</code>. The <code>value</code> can be a String, Buffer or Number. Strings are by
default interpreted as UTF8. Buffers will use the entire Buffer (to compare a
partial Buffer use <a href="#buffer_buf_slice_start_end"><code>buf.slice()</code></a>). Numbers will be interpreted as unsigned 8-bit
integer values between <code>0</code> and <code>255</code>.</p>
<pre><code class="lang-js">const buf = new Buffer(&#39;this is a buffer&#39;);

buf.indexOf(&#39;this&#39;);
  // returns 0
buf.indexOf(&#39;is&#39;);
  // returns 2
buf.indexOf(new Buffer(&#39;a buffer&#39;));
  // returns 8
buf.indexOf(97); // ascii for &#39;a&#39;
  // returns 8
buf.indexOf(new Buffer(&#39;a buffer example&#39;));
  // returns -1
buf.indexOf(new Buffer(&#39;a buffer example&#39;).slice(0,8));
  // returns 8

const utf16Buffer = new Buffer(&#39;\u039a\u0391\u03a3\u03a3\u0395&#39;, &#39;ucs2&#39;);

utf16Buffer.indexOf(&#39;\u03a3&#39;,  0, &#39;ucs2&#39;);
  // returns 4
utf16Buffer.indexOf(&#39;\u03a3&#39;, -4, &#39;ucs2&#39;);
  // returns 6
</code></pre>
<h3>buf.keys()<span><a class="mark" href="#buffer_buf_keys" id="buffer_buf_keys">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v1.1.0</span>
</div><ul>
<li>Returns: <span class="type">&lt;Iterator&gt;</span></li>
</ul>
<p>Creates and returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols">iterator</a> of Buffer keys (indices).</p>
<pre><code class="lang-js">const buf = new Buffer(&#39;buffer&#39;);
for (var key of buf.keys()) {
  console.log(key);
}
// prints:
//   0
//   1
//   2
//   3
//   4
//   5
</code></pre>
<h3>buf.length<span><a class="mark" href="#buffer_buf_length" id="buffer_buf_length">#</a></span></h3>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Returns the amount of memory allocated for the Buffer in number of bytes. Note
that this does not necessarily reflect the amount of usable data within the
Buffer. For instance, in the example below, a Buffer with 1234 bytes is
allocated, but only 11 ASCII bytes are written.</p>
<pre><code class="lang-js">const buf = new Buffer(1234);

console.log(buf.length);
  // Prints: 1234

buf.write(&#39;some string&#39;, 0, &#39;ascii&#39;);
console.log(buf.length);
  // Prints: 1234
</code></pre>
<p>While the <code>length</code> property is not immutable, changing the value of <code>length</code>
can result in undefined and inconsistent behavior. Applications that wish to
modify the length of a Buffer should therefore treat <code>length</code> as read-only and
use <a href="#buffer_buf_slice_start_end"><code>buf.slice()</code></a> to create a new Buffer.</p>
<pre><code class="lang-js">var buf = new Buffer(10);
buf.write(&#39;abcdefghj&#39;, 0, &#39;ascii&#39;);
console.log(buf.length);
  // Prints: 10
buf = buf.slice(0,5);
console.log(buf.length);
  // Prints: 5
</code></pre>
<h3>buf.readDoubleBE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readdoublebe_offset_noassert" id="buffer_buf_readdoublebe_offset_noassert">#</a></span></h3>
<h3>buf.readDoubleLE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readdoublele_offset_noassert" id="buffer_buf_readdoublele_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 8</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Reads a 64-bit double from the Buffer at the specified <code>offset</code> with specified
endian format (<code>readDoubleBE()</code> returns big endian, <code>readDoubleLE()</code> returns
little endian).</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<pre><code class="lang-js">const buf = new Buffer([1,2,3,4,5,6,7,8]);

buf.readDoubleBE();
  // Returns: 8.20788039913184e-304
buf.readDoubleLE();
  // Returns: 5.447603722011605e-270
buf.readDoubleLE(1);
  // throws RangeError: Index out of range

buf.readDoubleLE(1, true); // Warning: reads passed end of buffer!
  // Segmentation fault! don&#39;t do this!
</code></pre>
<h3>buf.readFloatBE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readfloatbe_offset_noassert" id="buffer_buf_readfloatbe_offset_noassert">#</a></span></h3>
<h3>buf.readFloatLE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readfloatle_offset_noassert" id="buffer_buf_readfloatle_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Reads a 32-bit float from the Buffer at the specified <code>offset</code> with specified
endian format (<code>readFloatBE()</code> returns big endian, <code>readFloatLE()</code> returns
little endian).</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<pre><code class="lang-js">const buf = new Buffer([1,2,3,4]);

buf.readFloatBE();
  // Returns: 2.387939260590663e-38
buf.readFloatLE();
  // Returns: 1.539989614439558e-36
buf.readFloatLE(1);
  // throws RangeError: Index out of range

buf.readFloatLE(1, true); // Warning: reads passed end of buffer!
  // Segmentation fault! don&#39;t do this!
</code></pre>
<h3>buf.readInt8(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readint8_offset_noassert" id="buffer_buf_readint8_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 1</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Reads a signed 8-bit integer from the Buffer at the specified <code>offset</code>.</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<p>Integers read from the Buffer are interpreted as two&#39;s complement signed values.</p>
<pre><code class="lang-js">const buf = new Buffer([1,-2,3,4]);

buf.readInt8(0);
  // returns 1
buf.readInt8(1);
  // returns -2
</code></pre>
<h3>buf.readInt16BE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readint16be_offset_noassert" id="buffer_buf_readint16be_offset_noassert">#</a></span></h3>
<h3>buf.readInt16LE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readint16le_offset_noassert" id="buffer_buf_readint16le_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 2</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Reads a signed 16-bit integer from the Buffer at the specified <code>offset</code> with
the specified endian format (<code>readInt16BE()</code> returns big endian,
<code>readInt16LE()</code> returns little endian).</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<p>Integers read from the Buffer are interpreted as two&#39;s complement signed values.</p>
<pre><code class="lang-js">const buf = new Buffer([1,-2,3,4]);

buf.readInt16BE();
  // returns 510
buf.readInt16LE(1);
  // returns 1022
</code></pre>
<h3>buf.readInt32BE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readint32be_offset_noassert" id="buffer_buf_readint32be_offset_noassert">#</a></span></h3>
<h3>buf.readInt32LE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readint32le_offset_noassert" id="buffer_buf_readint32le_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Reads a signed 32-bit integer from the Buffer at the specified <code>offset</code> with
the specified endian format (<code>readInt32BE()</code> returns big endian,
<code>readInt32LE()</code> returns little endian).</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<p>Integers read from the Buffer are interpreted as two&#39;s complement signed values.</p>
<pre><code class="lang-js">const buf = new Buffer([1,-2,3,4]);

buf.readInt32BE();
  // returns 33424132
buf.readInt32LE();
  // returns 67370497
buf.readInt32LE(1);
  // throws RangeError: Index out of range
</code></pre>
<h3>buf.readIntBE(offset, byteLength[, noAssert])<span><a class="mark" href="#buffer_buf_readintbe_offset_bytelength_noassert" id="buffer_buf_readintbe_offset_bytelength_noassert">#</a></span></h3>
<h3>buf.readIntLE(offset, byteLength[, noAssert])<span><a class="mark" href="#buffer_buf_readintle_offset_bytelength_noassert" id="buffer_buf_readintle_offset_bytelength_noassert">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v1.0.0</span>
</div><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - byteLength</code></li>
<li><code>byteLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt; byteLength &lt;= 6</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
<p>Reads <code>byteLength</code> number of bytes from the Buffer at the specified <code>offset</code>
and interprets the result as a two&#39;s complement signed value. Supports up to 48
bits of accuracy. For example:</p>
<pre><code class="lang-js">const buf = new Buffer(6);
buf.writeUInt16LE(0x90ab, 0);
buf.writeUInt32LE(0x12345678, 2);
buf.readIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)
// Returns: &#39;1234567890ab&#39;

buf.readIntBE(0, 6).toString(16);
// Returns: -546f87a9cbee
</code></pre>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<h3>buf.readUInt8(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readuint8_offset_noassert" id="buffer_buf_readuint8_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 1</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Reads an unsigned 8-bit integer from the Buffer at the specified <code>offset</code>.</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<pre><code class="lang-js">const buf = new Buffer([1,-2,3,4]);

buf.readUInt8(0);
  // returns 1
buf.readUInt8(1);
  // returns 254
</code></pre>
<h3>buf.readUInt16BE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readuint16be_offset_noassert" id="buffer_buf_readuint16be_offset_noassert">#</a></span></h3>
<h3>buf.readUInt16LE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readuint16le_offset_noassert" id="buffer_buf_readuint16le_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 2</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Reads an unsigned 16-bit integer from the Buffer at the specified <code>offset</code> with
specified endian format (<code>readUInt16BE()</code> returns big endian,
<code>readUInt16LE()</code> returns little endian).</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<p>Example:</p>
<pre><code class="lang-js">const buf = new Buffer([0x3, 0x4, 0x23, 0x42]);

buf.readUInt16BE(0);
  // Returns: 0x0304
buf.readUInt16LE(0);
  // Returns: 0x0403
buf.readUInt16BE(1);
  // Returns: 0x0423
buf.readUInt16LE(1);
  // Returns: 0x2304
buf.readUInt16BE(2);
  // Returns: 0x2342
buf.readUInt16LE(2);
  // Returns: 0x4223
</code></pre>
<h3>buf.readUInt32BE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readuint32be_offset_noassert" id="buffer_buf_readuint32be_offset_noassert">#</a></span></h3>
<h3>buf.readUInt32LE(offset[, noAssert])<span><a class="mark" href="#buffer_buf_readuint32le_offset_noassert" id="buffer_buf_readuint32le_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
</div><p>Reads an unsigned 32-bit integer from the Buffer at the specified <code>offset</code> with
specified endian format (<code>readUInt32BE()</code> returns big endian,
<code>readUInt32LE()</code> returns little endian).</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<p>Example:</p>
<pre><code class="lang-js">const buf = new Buffer([0x3, 0x4, 0x23, 0x42]);

buf.readUInt32BE(0);
  // Returns: 0x03042342
console.log(buf.readUInt32LE(0));
  // Returns: 0x42230403
</code></pre>
<h3>buf.readUIntBE(offset, byteLength[, noAssert])<span><a class="mark" href="#buffer_buf_readuintbe_offset_bytelength_noassert" id="buffer_buf_readuintbe_offset_bytelength_noassert">#</a></span></h3>
<h3>buf.readUIntLE(offset, byteLength[, noAssert])<span><a class="mark" href="#buffer_buf_readuintle_offset_bytelength_noassert" id="buffer_buf_readuintle_offset_bytelength_noassert">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v1.0.0</span>
</div><ul>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - byteLength</code></li>
<li><code>byteLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt; byteLength &lt;= 6</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a></li>
</ul>
<p>Reads <code>byteLength</code> number of bytes from the Buffer at the specified <code>offset</code>
and interprets the result as an unsigned integer. Supports up to 48
bits of accuracy. For example:</p>
<pre><code class="lang-js">const buf = new Buffer(6);
buf.writeUInt16LE(0x90ab, 0);
buf.writeUInt32LE(0x12345678, 2);
buf.readUIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)
// Returns: &#39;1234567890ab&#39;

buf.readUIntBE(0, 6).toString(16);
// Returns: ab9078563412
</code></pre>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.</p>
<h3>buf.slice([start[, end]])<span><a class="mark" href="#buffer_buf_slice_start_end" id="buffer_buf_slice_start_end">#</a></span></h3>
<div class="signature"><ul>
<li><code>start</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: 0</li>
<li><code>end</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: <code>buffer.length</code></li>
<li>Returns: <a href="buffer.html#buffer_class_buffer" class="type">&lt;Buffer&gt;</a></li>
</ul>
</div><p>Returns a new Buffer that references the same memory as the original, but
offset and cropped by the <code>start</code> and <code>end</code> indices.</p>
<p><strong>Note that modifying the new Buffer slice will modify the memory in the
original Buffer because the allocated memory of the two objects overlap.</strong></p>
<p>Example: build a Buffer with the ASCII alphabet, take a slice, then modify one
byte from the original Buffer.</p>
<pre><code class="lang-js">const buf1 = new Buffer(26);

for (var i = 0 ; i &lt; 26 ; i++) {
  buf1[i] = i + 97; // 97 is ASCII a
}

const buf2 = buf1.slice(0, 3);
buf2.toString(&#39;ascii&#39;, 0, buf2.length);
  // Returns: &#39;abc&#39;
buf1[0] = 33;
buf2.toString(&#39;ascii&#39;, 0, buf2.length);
  // Returns : &#39;!bc&#39;
</code></pre>
<p>Specifying negative indexes causes the slice to be generated relative to the
end of the Buffer rather than the beginning.</p>
<pre><code class="lang-js">const buf = new Buffer(&#39;buffer&#39;);

buf.slice(-6, -1).toString();
  // Returns &#39;buffe&#39;, equivalent to buf.slice(0, 5)
buf.slice(-6, -2).toString();
  // Returns &#39;buff&#39;, equivalent to buf.slice(0, 4)
buf.slice(-5, -2).toString();
  // Returns &#39;uff&#39;, equivalent to buf.slice(1, 4)
</code></pre>
<h3>buf.toString([encoding[, start[, end]]])<span><a class="mark" href="#buffer_buf_tostring_encoding_start_end" id="buffer_buf_tostring_encoding_start_end">#</a></span></h3>
<div class="signature"><ul>
<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> Default: <code>&#39;utf8&#39;</code></li>
<li><code>start</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: 0</li>
<li><code>end</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: <code>buffer.length</code></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a></li>
</ul>
</div><p>Decodes and returns a string from the Buffer data using the specified
character set <code>encoding</code>.</p>
<pre><code class="lang-js">const buf = new Buffer(26);
for (var i = 0 ; i &lt; 26 ; i++) {
  buf[i] = i + 97; // 97 is ASCII a
}
buf.toString(&#39;ascii&#39;);
  // Returns: &#39;abcdefghijklmnopqrstuvwxyz&#39;
buf.toString(&#39;ascii&#39;,0,5);
  // Returns: &#39;abcde&#39;
buf.toString(&#39;utf8&#39;,0,5);
  // Returns: &#39;abcde&#39;
buf.toString(undefined,0,5);
  // Returns: &#39;abcde&#39;, encoding defaults to &#39;utf8&#39;
</code></pre>
<h3>buf.toJSON()<span><a class="mark" href="#buffer_buf_tojson" id="buffer_buf_tojson">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.9.2</span>
</div><ul>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Returns a JSON representation of the Buffer instance.  <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify"><code>JSON.stringify()</code></a>
implicitly calls this function when stringifying a Buffer instance.</p>
<p>Example:</p>
<pre><code class="lang-js">const buf = new Buffer(&#39;test&#39;);
const json = JSON.stringify(buf);

console.log(json);
// Prints: &#39;{&quot;type&quot;:&quot;Buffer&quot;,&quot;data&quot;:[116,101,115,116]}&#39;

const copy = JSON.parse(json, (key, value) =&gt; {
    return value &amp;&amp; value.type === &#39;Buffer&#39;
      ? new Buffer(value.data)
      : value;
  });

console.log(copy.toString());
// Prints: &#39;test&#39;
</code></pre>
<h3>buf.values()<span><a class="mark" href="#buffer_buf_values" id="buffer_buf_values">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v1.1.0</span>
</div><ul>
<li>Returns: <span class="type">&lt;Iterator&gt;</span></li>
</ul>
<p>Creates and returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols">iterator</a> for Buffer values (bytes). This function is
called automatically when the Buffer is used in a <code>for..of</code> statement.</p>
<pre><code class="lang-js">const buf = new Buffer(&#39;buffer&#39;);
for (var value of buf.values()) {
  console.log(value);
}
// prints:
//   98
//   117
//   102
//   102
//   101
//   114

for (var value of buf) {
  console.log(value);
}
// prints:
//   98
//   117
//   102
//   102
//   101
//   114
</code></pre>
<h3>buf.write(string[, offset[, length]][, encoding])<span><a class="mark" href="#buffer_buf_write_string_offset_length_encoding" id="buffer_buf_write_string_offset_length_encoding">#</a></span></h3>
<div class="signature"><ul>
<li><code>string</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> Bytes to be written to buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: 0</li>
<li><code>length</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: <code>buffer.length - offset</code></li>
<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a> Default: <code>&#39;utf8&#39;</code></li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Numbers of bytes written</li>
</ul>
</div><p>Writes <code>string</code> to the Buffer at <code>offset</code> using the given <code>encoding</code>.
The <code>length</code> parameter is the number of bytes to write. If the Buffer did not
contain enough space to fit the entire string, only a partial amount of the
string will be written however, it will not write only partially encoded
characters.</p>
<pre><code class="lang-js">const buf = new Buffer(256);
const len = buf.write(&#39;\u00bd + \u00bc = \u00be&#39;, 0);
console.log(`${len} bytes: ${buf.toString(&#39;utf8&#39;, 0, len)}`);
  // Prints: 12 bytes: ½ + ¼ = ¾
</code></pre>
<h3>buf.writeDoubleBE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writedoublebe_value_offset_noassert" id="buffer_buf_writedoublebe_value_offset_noassert">#</a></span></h3>
<h3>buf.writeDoubleLE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writedoublele_value_offset_noassert" id="buffer_buf_writedoublele_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 8</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
</div><p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeDoubleBE()</code> writes big endian, <code>writeDoubleLE()</code> writes little
endian). The <code>value</code> argument <em>should</em> be a valid 64-bit double. Behavior is
not defined when <code>value</code> is anything other than a 64-bit double.</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>Example:</p>
<pre><code class="lang-js">const buf = new Buffer(8);
buf.writeDoubleBE(0xdeadbeefcafebabe, 0);

console.log(buf);
  // Prints: &lt;Buffer 43 eb d5 b7 dd f9 5f d7&gt;

buf.writeDoubleLE(0xdeadbeefcafebabe, 0);

console.log(buf);
  // Prints: &lt;Buffer d7 5f f9 dd b7 d5 eb 43&gt;
</code></pre>
<h3>buf.writeFloatBE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writefloatbe_value_offset_noassert" id="buffer_buf_writefloatbe_value_offset_noassert">#</a></span></h3>
<h3>buf.writeFloatLE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writefloatle_value_offset_noassert" id="buffer_buf_writefloatle_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
</div><p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeFloatBE()</code> writes big endian, <code>writeFloatLE()</code> writes little
endian). Behavior is not defined when <code>value</code> is anything other than a 32-bit
float.</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>Example:</p>
<pre><code class="lang-js">const buf = new Buffer(4);
buf.writeFloatBE(0xcafebabe, 0);

console.log(buf);
  // Prints: &lt;Buffer 4f 4a fe bb&gt;

buf.writeFloatLE(0xcafebabe, 0);

console.log(buf);
  // Prints: &lt;Buffer bb fe 4a 4f&gt;
</code></pre>
<h3>buf.writeInt8(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeint8_value_offset_noassert" id="buffer_buf_writeint8_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 1</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
</div><p>Writes <code>value</code> to the Buffer at the specified <code>offset</code>. The <code>value</code> should be a
valid signed 8-bit integer.  Behavior is not defined when <code>value</code> is anything
other than a signed 8-bit integer.</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>The <code>value</code> is interpreted and written as a two&#39;s complement signed integer.</p>
<pre><code class="lang-js">const buf = new Buffer(2);
buf.writeInt8(2, 0);
buf.writeInt8(-2, 1);
console.log(buf);
  // Prints: &lt;Buffer 02 fe&gt;
</code></pre>
<h3>buf.writeInt16BE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeint16be_value_offset_noassert" id="buffer_buf_writeint16be_value_offset_noassert">#</a></span></h3>
<h3>buf.writeInt16LE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeint16le_value_offset_noassert" id="buffer_buf_writeint16le_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 2</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
</div><p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeInt16BE()</code> writes big endian, <code>writeInt16LE()</code> writes little
endian). The <code>value</code> should be a valid signed 16-bit integer. Behavior is
not defined when <code>value</code> is anything other than a signed 16-bit integer.</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>The <code>value</code> is interpreted and written as a two&#39;s complement signed integer.</p>
<pre><code class="lang-js">const buf = new Buffer(4);
buf.writeInt16BE(0x0102,0);
buf.writeInt16LE(0x0304,2);
console.log(buf);
  // Prints: &lt;Buffer 01 02 04 03&gt;
</code></pre>
<h3>buf.writeInt32BE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeint32be_value_offset_noassert" id="buffer_buf_writeint32be_value_offset_noassert">#</a></span></h3>
<h3>buf.writeInt32LE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeint32le_value_offset_noassert" id="buffer_buf_writeint32le_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
</div><p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeInt32BE()</code> writes big endian, <code>writeInt32LE()</code> writes little
endian). The <code>value</code> should be a valid signed 32-bit integer. Behavior is
not defined when <code>value</code> is anything other than a signed 32-bit integer.</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>The <code>value</code> is interpreted and written as a two&#39;s complement signed integer.</p>
<pre><code class="lang-js">const buf = new Buffer(8);
buf.writeInt32BE(0x01020304,0);
buf.writeInt32LE(0x05060708,4);
console.log(buf);
  // Prints: &lt;Buffer 01 02 03 04 08 07 06 05&gt;
</code></pre>
<h3>buf.writeIntBE(value, offset, byteLength[, noAssert])<span><a class="mark" href="#buffer_buf_writeintbe_value_offset_bytelength_noassert" id="buffer_buf_writeintbe_value_offset_bytelength_noassert">#</a></span></h3>
<h3>buf.writeIntLE(value, offset, byteLength[, noAssert])<span><a class="mark" href="#buffer_buf_writeintle_value_offset_bytelength_noassert" id="buffer_buf_writeintle_value_offset_bytelength_noassert">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v1.0.0</span>
</div><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - byteLength</code></li>
<li><code>byteLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt; byteLength &lt;= 6</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> and <code>byteLength</code>.
Supports up to 48 bits of accuracy. For example:</p>
<pre><code class="lang-js">const buf1 = new Buffer(6);
buf1.writeUIntBE(0x1234567890ab, 0, 6);
console.log(buf1);
  // Prints: &lt;Buffer 12 34 56 78 90 ab&gt;

const buf2 = new Buffer(6);
buf2.writeUIntLE(0x1234567890ab, 0, 6);
console.log(buf2);
  // Prints: &lt;Buffer ab 90 78 56 34 12&gt;
</code></pre>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>Behavior is not defined when <code>value</code> is anything other than an integer.</p>
<h3>buf.writeUInt8(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeuint8_value_offset_noassert" id="buffer_buf_writeuint8_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 1</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
</div><p>Writes <code>value</code> to the Buffer at the specified <code>offset</code>. The <code>value</code> should be a
valid unsigned 8-bit integer.  Behavior is not defined when <code>value</code> is anything
other than an unsigned 8-bit integer.</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>Example:</p>
<pre><code class="lang-js">const buf = new Buffer(4);
buf.writeUInt8(0x3, 0);
buf.writeUInt8(0x4, 1);
buf.writeUInt8(0x23, 2);
buf.writeUInt8(0x42, 3);

console.log(buf);
  // Prints: &lt;Buffer 03 04 23 42&gt;
</code></pre>
<h3>buf.writeUInt16BE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeuint16be_value_offset_noassert" id="buffer_buf_writeuint16be_value_offset_noassert">#</a></span></h3>
<h3>buf.writeUInt16LE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeuint16le_value_offset_noassert" id="buffer_buf_writeuint16le_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 2</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
</div><p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeUInt16BE()</code> writes big endian, <code>writeUInt16LE()</code> writes little
endian). The <code>value</code> should be a valid unsigned 16-bit integer. Behavior is
not defined when <code>value</code> is anything other than an unsigned 16-bit integer.</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>Example:</p>
<pre><code class="lang-js">const buf = new Buffer(4);
buf.writeUInt16BE(0xdead, 0);
buf.writeUInt16BE(0xbeef, 2);

console.log(buf);
  // Prints: &lt;Buffer de ad be ef&gt;

buf.writeUInt16LE(0xdead, 0);
buf.writeUInt16LE(0xbeef, 2);

console.log(buf);
  // Prints: &lt;Buffer ad de ef be&gt;
</code></pre>
<h3>buf.writeUInt32BE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeuint32be_value_offset_noassert" id="buffer_buf_writeuint32be_value_offset_noassert">#</a></span></h3>
<h3>buf.writeUInt32LE(value, offset[, noAssert])<span><a class="mark" href="#buffer_buf_writeuint32le_value_offset_noassert" id="buffer_buf_writeuint32le_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
</div><p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeUInt32BE()</code> writes big endian, <code>writeUInt32LE()</code> writes little
endian). The <code>value</code> should be a valid unsigned 32-bit integer. Behavior is
not defined when <code>value</code> is anything other than an unsigned 32-bit integer.</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>Example:</p>
<pre><code class="lang-js">const buf = new Buffer(4);
buf.writeUInt32BE(0xfeedface, 0);

console.log(buf);
  // Prints: &lt;Buffer fe ed fa ce&gt;

buf.writeUInt32LE(0xfeedface, 0);

console.log(buf);
  // Prints: &lt;Buffer ce fa ed fe&gt;
</code></pre>
<h3>buf.writeUIntBE(value, offset, byteLength[, noAssert])<span><a class="mark" href="#buffer_buf_writeuintbe_value_offset_bytelength_noassert" id="buffer_buf_writeuintbe_value_offset_bytelength_noassert">#</a></span></h3>
<h3>buf.writeUIntLE(value, offset, byteLength[, noAssert])<span><a class="mark" href="#buffer_buf_writeuintle_value_offset_bytelength_noassert" id="buffer_buf_writeuintle_value_offset_bytelength_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Bytes to be written to Buffer</li>
<li><code>offset</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt;= offset &lt;= buf.length - byteLength</code></li>
<li><code>byteLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> <code>0 &lt; byteLength &lt;= 6</code></li>
<li><code>noAssert</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;Boolean&gt;</a> Default: false</li>
<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> The offset plus the number of written bytes</li>
</ul>
</div><p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> and <code>byteLength</code>.
Supports up to 48 bits of accuracy. For example:</p>
<pre><code class="lang-js">const buf = new Buffer(6);
buf.writeUIntBE(0x1234567890ab, 0, 6);
console.log(buf);
  // Prints: &lt;Buffer 12 34 56 78 90 ab&gt;
</code></pre>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.</p>
<p>Behavior is not defined when <code>value</code> is anything other than an unsigned integer.</p>
<h2>buffer.INSPECT_MAX_BYTES<span><a class="mark" href="#buffer_buffer_inspect_max_bytes" id="buffer_buffer_inspect_max_bytes">#</a></span></h2>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;Number&gt;</a> Default: 50</li>
</ul>
</div><p>Returns the maximum number of bytes that will be returned when
<code>buffer.inspect()</code> is called. This can be overridden by user modules. See
<a href="util.html#util_util_inspect_object_options"><code>util.inspect()</code></a> for more details on <code>buffer.inspect()</code> behavior.</p>
<p>Note that this is a property on the <code>buffer</code> module as returned by
<code>require(&#39;buffer&#39;)</code>, not on the Buffer global or a Buffer instance.</p>
<h2>Class: SlowBuffer<span><a class="mark" href="#buffer_class_slowbuffer" id="buffer_class_slowbuffer">#</a></span></h2>
<p>Returns an un-pooled <code>Buffer</code>.</p>
<p>In order to avoid the garbage collection overhead of creating many individually
allocated Buffers, by default allocations under 4KB are sliced from a single
larger allocated object. This approach improves both performance and memory
usage since v8 does not need to track and cleanup as many <code>Persistent</code> objects.</p>
<p>In the case where a developer may need to retain a small chunk of memory from a
pool for an indeterminate amount of time, it may be appropriate to create an
un-pooled Buffer instance using <code>SlowBuffer</code> then copy out the relevant bits.</p>
<pre><code class="lang-js">// need to keep around a few small chunks of memory
const store = [];

socket.on(&#39;readable&#39;, () =&gt; {
  var data = socket.read();
  // allocate for retained data
  var sb = new SlowBuffer(10);
  // copy the data into the new allocation
  data.copy(sb, 0, 0, 10);
  store.push(sb);
});
</code></pre>
<p>Use of <code>SlowBuffer</code> should be used only as a last resort <em>after</em> a developer
has observed undue memory retention in their applications.</p>
<h3>new SlowBuffer(size)<span><a class="mark" href="#buffer_new_slowbuffer_size" id="buffer_new_slowbuffer_size">#</a></span></h3>
<div class="signature"><ul>
<li><code>size</code> Number</li>
</ul>
</div><p>Allocates a new <code>SlowBuffer</code> of <code>size</code> bytes.  The <code>size</code> must be less than
or equal to the value of <code>require(&#39;buffer&#39;).kMaxLength</code> (on 64-bit
architectures, <code>kMaxLength</code> is <code>(2^31)-1</code>). Otherwise, a <a href="errors.html#errors_class_rangeerror"><code>RangeError</code></a> is
thrown. If a <code>size</code> less than 0 is specified, a zero-length <code>SlowBuffer</code> will be
created.</p>
<p>The underlying memory for <code>SlowBuffer</code> instances is <em>not initialized</em>. The
contents of a newly created <code>SlowBuffer</code> are unknown and could contain
sensitive data. Use <a href="#buffer_buf_fill_value_offset_end"><code>buf.fill(0)</code></a> to initialize a <code>SlowBuffer</code> to zeroes.</p>
<pre><code class="lang-js">const SlowBuffer = require(&#39;buffer&#39;).SlowBuffer;
const buf = new SlowBuffer(5);
console.log(buf);
  // &lt;Buffer 78 e0 82 02 01&gt;
  // (octets will be different, every time)
buf.fill(0);
console.log(buf);
  // &lt;Buffer 00 00 00 00 00&gt;
</code></pre>

      </div>
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
  <!-- __TRACKING__ -->
</body>
</html>