forked from KOBA789/node.js_ja
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuffer.html
More file actions
1420 lines (1169 loc) · 58.9 KB
/
Copy pathbuffer.html
File metadata and controls
1420 lines (1169 loc) · 58.9 KB
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
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Buffer Node.js v0.11.11 Manual & Documentation</title>
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/sh.css">
<link rel="canonical" href="http://nodejs.org/api/buffer.html">
</head>
<body class="alt apidoc" id="api-section-buffer">
<div id="intro" class="interior">
<a href="/" title="Go back to the home page">
<img id="logo" src="http://nodejs.org/images/logo-light.png" alt="node.js">
</a>
</div>
<div id="content" class="clearfix">
<div id="column2" class="interior">
<ul>
<!--
<li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li>
<li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li>
<li><a href="/logos/" class="logos">Logos</a></li>
-->
<li><a href="../" class="home">ホーム</a></li>
<li><a href="../#download" class="download">ダウンロード</a></li>
<li><a href="../about/" class="about">概要</a></li>
<li><a href="http://npmjs.org/" class="npm">npm レジストリ</a></li>
<li><a href="../api/" class="docs current">ドキュメント</a></li>
<li><a href="http://blog.nodejs.org" class="blog">ブログ</a></li>
<li><a href="../community/" class="community">コミュニティ</a></li>
<li><a href="../logos/" class="logos">ロゴ</a></li>
<li><a href="http://jobs.nodejs.org/" class="jobs">Jobs</a></li>
</ul>
<p class="twitter"><a href="http://twitter.com/nodejs">@nodejs</a></p>
</div>
<div id="column1" class="interior">
<header>
<h1>Node.js v0.11.11 マニュアル & ドキュメンテーション</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><a href="#buffer_buffer">Buffer</a><ul>
<li><a href="#buffer_class_buffer">Class: Buffer</a><ul>
<li><a href="#buffer_new_buffer_size">new Buffer(size)</a></li>
<li><a href="#buffer_new_buffer_array">new Buffer(array)</a></li>
<li><a href="#buffer_new_buffer_str_encoding">new Buffer(str, [encoding])</a></li>
<li><a href="#buffer_class_method_buffer_isencoding_encoding">Class Method: Buffer.isEncoding(encoding)</a></li>
<li><a href="#buffer_class_method_buffer_isbuffer_obj">Class Method: Buffer.isBuffer(obj)</a></li>
<li><a href="#buffer_class_method_buffer_bytelength_string_encoding">Class Method: Buffer.byteLength(string, [encoding])</a></li>
<li><a href="#buffer_class_method_buffer_concat_list_totallength">Class Method: Buffer.concat(list, [totalLength])</a></li>
<li><a href="#buffer_buf_length">buf.length</a></li>
<li><a href="#buffer_buf_write_string_offset_length_encoding">buf.write(string, [offset], [length], [encoding])</a></li>
<li><a href="#buffer_buf_tostring_encoding_start_end">buf.toString([encoding], [start], [end])</a></li>
<li><a href="#buffer_buf_tojson">buf.toJSON()</a></li>
<li><a href="#buffer_buf_index">buf[index]</a></li>
<li><a href="#buffer_buf_copy_targetbuffer_targetstart_sourcestart_sourceend">buf.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])</a></li>
<li><a href="#buffer_buf_slice_start_end">buf.slice([start], [end])</a></li>
<li><a href="#buffer_buf_readuint8_offset_noassert">buf.readUInt8(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readuint16le_offset_noassert">buf.readUInt16LE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readuint16be_offset_noassert">buf.readUInt16BE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readuint32le_offset_noassert">buf.readUInt32LE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readuint32be_offset_noassert">buf.readUInt32BE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readint8_offset_noassert">buf.readInt8(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readint16le_offset_noassert">buf.readInt16LE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readint16be_offset_noassert">buf.readInt16BE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readint32le_offset_noassert">buf.readInt32LE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readint32be_offset_noassert">buf.readInt32BE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readfloatle_offset_noassert">buf.readFloatLE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readfloatbe_offset_noassert">buf.readFloatBE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readdoublele_offset_noassert">buf.readDoubleLE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_readdoublebe_offset_noassert">buf.readDoubleBE(offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeuint8_value_offset_noassert">buf.writeUInt8(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeuint16le_value_offset_noassert">buf.writeUInt16LE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeuint16be_value_offset_noassert">buf.writeUInt16BE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeuint32le_value_offset_noassert">buf.writeUInt32LE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeuint32be_value_offset_noassert">buf.writeUInt32BE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeint8_value_offset_noassert">buf.writeInt8(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeint16le_value_offset_noassert">buf.writeInt16LE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeint16be_value_offset_noassert">buf.writeInt16BE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeint32le_value_offset_noassert">buf.writeInt32LE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writeint32be_value_offset_noassert">buf.writeInt32BE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writefloatle_value_offset_noassert">buf.writeFloatLE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writefloatbe_value_offset_noassert">buf.writeFloatBE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writedoublele_value_offset_noassert">buf.writeDoubleLE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_writedoublebe_value_offset_noassert">buf.writeDoubleBE(value, offset, [noAssert])</a></li>
<li><a href="#buffer_buf_fill_value_offset_end">buf.fill(value, [offset], [end])</a></li>
<li><a href="#buffer_buf_toarraybuffer">buf.toArrayBuffer()</a></li>
</ul>
</li>
<li><a href="#buffer_buffer_inspect_max_bytes">buffer.INSPECT_MAX_BYTES</a></li>
<li><a href="#buffer_class_slowbuffer">Class: SlowBuffer</a></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_3">Stability: 3 - Stable</pre><!--
Pure JavaScript is Unicode friendly but not nice to binary data. When
dealing with TCP streams or the file system, it's necessary to handle octet
streams. Node has several strategies for manipulating, creating, and
consuming octet streams.
-->
<p>純粋な JavaScript は Unicode と相性がいいものの、バイナリデータの扱いはうまくありません。
TCP ストリームやファイルシステムを扱う場合は、オクテットストリームを処理する必要があります。
Node にはオクテットストリームを操作、作成、消費するためにいくつかの戦略があります。
</p>
<!--
Raw data is stored in instances of the `Buffer` class. A `Buffer` is similar
to an array of integers but corresponds to a raw memory allocation outside
the V8 heap. A `Buffer` cannot be resized.
-->
<p>生のデータは <code>Buffer</code> クラスのインスタンスに保存されます。
<code>Buffer</code> は整数の配列と似ていますが、
V8 ヒープの外部に割り当てられた生のメモリに対応します。
<code>Buffer</code> のサイズを変更することはできません。
</p>
<!--
The `Buffer` class is a global, making it very rare that one would need
to ever `require('buffer')`.
-->
<p><code>Buffer</code> クラスはグローバルなので、<code>require('buffer')</code> が必要になることは
ほとんどありません。
</p>
<!--
Converting between Buffers and JavaScript string objects requires an explicit
encoding method. Here are the different string encodings.
-->
<p>バッファを JavaScript 文字列オブジェクトとの間で変換するにはエンコーディング方式を明示する必要があります。
いくつかのエンコーディング方式があります。
</p>
<!--
* `'ascii'` - for 7 bit ASCII data only. This encoding method is very fast, and
will strip the high bit if set.
* `'utf8'` - Multibyte encoded Unicode characters. Many web pages and other
document formats use UTF-8.
* `'utf16le'` - 2 or 4 bytes, little endian encoded Unicode characters.
Surrogate pairs (U+10000 to U+10FFFF) are supported.
* `'ucs2'` - Alias of `'utf16le'`.
* `'base64'` - Base64 string encoding.
* `'binary'` - A way of encoding raw binary data into strings by using only
the first 8 bits of each character. This encoding method is deprecated and
should be avoided in favor of `Buffer` objects where possible. This encoding
will be removed in future versions of Node.
* `'hex'` - Encode each byte as two hexadecimal characters.
-->
<ul>
<li><p><code>'ascii'</code> - 7bit の ASCII データ専用です。
このエンコーディング方式はとても高速で、もし上位ビットがセットされていれば取り除かれます。</p>
</li>
<li><p><code>'utf8'</code> - 可変長のバイト単位でエンコードされたUnicode文字。
多くのWebページやその他のドキュメントは UTF-8 を使っています。</p>
</li>
<li><p><code>'utf16le'</code> - 2 または 4 バイトのリトルエンディアンでエンコードされた
Unicode 文字。
サロゲートペア (U+10000~U+10FFFF) もサポートされます。</p>
</li>
<li><p><code>'ucs2'</code> - <code>'utf16le'</code> の別名です。</p>
</li>
<li><p><code>'base64'</code> - Base64 文字列エンコーディング.</p>
</li>
<li><p><code>'binary'</code> - 生のバイナリデータを各文字の最初の 8bit として使用するエンコーディング方式。
このエンコーディング方式はもはや価値がなく、<code>Buffer</code> オブジェクトでは可能な限り使用すべきではありません。
このエンコーディングは、Node の将来のバージョンで削除される予定です。</p>
</li>
<li><p><code>'hex'</code> - 各バイトを 2 桁の16進数文字列でエンコードします。</p>
</li>
</ul>
<h2>Class: Buffer<span><a class="mark" href="#buffer_class_buffer" id="buffer_class_buffer">#</a></span></h2>
<!--
The Buffer class is a global type for dealing with binary data directly.
It can be constructed in a variety of ways.
-->
<p>Buffer クラスはバイナリデータを直接扱うためのグローバルな型です。
それは様々な方法で構築することができます。
</p>
<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> Number</li>
</div></ul>
<!--
Allocates a new buffer of `size` octets.
-->
<p><code>size</code> オクテットの新しいバッファを割り当てます。
</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> Array</li>
</div></ul>
<!--
Allocates a new buffer using an `array` of octets.
-->
<p>オクテットの <code>array</code> を使用する新しいバッファを割り当てます。
</p>
<h3>new Buffer(str, [encoding])<span><a class="mark" href="#buffer_new_buffer_str_encoding" id="buffer_new_buffer_str_encoding">#</a></span></h3>
<!--
* `str` String - string to encode.
* `encoding` String - encoding to use, Optional.
-->
<ul>
<li><code>str</code> String - エンコードされる文字列</li>
<li><code>encoding</code> String - 使用するエンコード、Optional、Default: 'utf8'</li>
</ul>
<!--
Allocates a new buffer containing the given `str`.
`encoding` defaults to `'utf8'`.
-->
<p>与えられた <code>str</code> を内容とする新しいバッファを割り当てます。
<code>encoding</code> のデフォルトは <code>'utf8'</code> です。
</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>
<!--
* `encoding` {String} The encoding string to test
-->
<ul>
<li><code>encoding</code> {String} 検証するエンコーディング名</li>
</ul>
<!--
Returns true if the `encoding` is a valid encoding argument, or false
otherwise.
-->
<p><code>encoding</code> が正しければ <code>true</code>、それ以外は <code>false</code> を返します。
</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> Object</li>
<li>Return: Boolean</li>
</div></ul>
<!--
Tests if `obj` is a `Buffer`.
-->
<p><code>obj</code> が <code>Buffer</code> かどうかテストします。
</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>
<!--
* `string` String
* `encoding` String, Optional, Default: 'utf8'
* Return: Number
-->
<ul>
<li><code>string</code> String</li>
<li><code>encoding</code> String, 任意, デフォルト: 'utf8'</li>
<li>Return: Number</li>
</ul>
<!--
Gives the actual byte length of a string. `encoding` defaults to `'utf8'`.
This is not the same as `String.prototype.length` since that returns the
number of *characters* in a string.
-->
<p>文字列の実際のバイト数を返します。<code>encoding</code> のデフォルトは <code>'utf8'</code> です。
これは文字列の<em>文字</em>数を返す <code>String.prototype.length</code> と同じではありません。
</p>
<!--
Example:
-->
<p>例:
</p>
<pre><code>str = '\u00bd + \u00bc = \u00be';
console.log(str + ": " + str.length + " characters, " +
Buffer.byteLength(str, 'utf8') + " bytes");
// ½ + ¼ = ¾: 9 characters, 12 bytes</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>
<!--
* `list` {Array} List of Buffer objects to concat
* `totalLength` {Number} Total length of the buffers when concatenated
-->
<ul>
<li><code>list</code> {Array} 結合するバッファのリスト</li>
<li><code>totalLength</code> {Number} 結合されるバッファ全体の長さ</li>
</ul>
<!--
Returns a buffer which is the result of concatenating all the buffers in
the list together.
-->
<p>リストに含まれるバッファ全体を結合した結果のバッファを返します。
</p>
<!--
If the list has no items, or if the totalLength is 0, then it returns a
zero-length buffer.
-->
<p>リストが空の場合、または <code>totalLength</code> が 0 の場合は長さが
0 のバッファを返します。
</p>
<!--
If the list has exactly one item, then the first item of the list is
returned.
-->
<p>リストが一つだけの要素を持つ場合、リストの先頭要素が返されます。
</p>
<!--
If the list has more than one item, then a new Buffer is created.
-->
<p>リストが複数の要素を持つ場合、新しいバッファが作成されます。
</p>
<!--
If totalLength is not provided, it is read from the buffers in the list.
However, this adds an additional loop to the function, so it is faster
to provide the length explicitly.
-->
<p><code>totalLength</code> が与えられない場合はリスト中のバッファから求められます。
しかし、これは余計なループが必要になるため、明示的に長さを指定する方が
高速です。
</p>
<h3>buf.length<span><a class="mark" href="#buffer_buf_length" id="buffer_buf_length">#</a></span></h3>
<div class="signature"><ul>
<li>Number</li>
</div></ul>
<!--
The size of the buffer in bytes. Note that this is not necessarily the size
of the contents. `length` refers to the amount of memory allocated for the
buffer object. It does not change when the contents of the buffer are changed.
-->
<p>バイト数によるバッファのサイズ。
これは実際の内容のサイズではないことに注意してください。
<code>length</code> はバッファオブジェクトに割り当てられたメモリ全体を参照します。
</p>
<pre><code>buf = new Buffer(1234);
console.log(buf.length);
buf.write("some string", 0, "ascii");
console.log(buf.length);
// 1234
// 1234</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>
<!--
* `string` String - data to be written to buffer
* `offset` Number, Optional, Default: 0
* `length` Number, Optional, Default: `buffer.length - offset`
* `encoding` String, Optional, Default: 'utf8'
-->
<ul>
<li><code>string</code> String - バッファに書き込まれるデータ</li>
<li><code>offset</code> Number, Optional, Default: 0</li>
<li><code>length</code> Number, Optional</li>
<li><code>encoding</code> String, Optional, Default: 'utf8'</li>
</ul>
<!--
Writes `string` to the buffer at `offset` using the given encoding.
`offset` defaults to `0`, `encoding` defaults to `'utf8'`. `length` is
the number of bytes to write. Returns number of octets written. If `buffer` did
not contain enough space to fit the entire string, it will write a partial
amount of the string. `length` defaults to `buffer.length - offset`.
The method will not write partial characters.
-->
<p>与えられたエンコーディングを使用して、<code>string</code> をバッファの <code>offset</code> から書き込みます。
<code>offset</code> のデフォルトは <code>0</code>、<code>encoding</code> のデフォルトは <code>'utf8'</code> です。
<code>length</code> は書き込むバイト数です。書き込まれたオクテット数を返します。
もし <code>buffer</code> が文字列全体を挿入するのに十分なスペースを含んでいなければ、文字列の一部だけを書き込みます。
<code>length</code> のデフォルトは <code>buffer.length - offset</code> です。
このメソッドは文字の一部だけを書き込むことはありません。
</p>
<!--
Example: write a utf8 string into a buffer, then print it
-->
<p>例: utf8 の文字列をバッファに書き込み、それをプリントします
</p>
<pre><code>buf = new Buffer(256);
len = buf.write('\u00bd + \u00bc = \u00be', 0);
console.log(len + " bytes: " + buf.toString('utf8', 0, len));</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> String, Optional, Default: 'utf8'</li>
<li><code>start</code> Number, Optional, Default: 0</li>
<li><code>end</code> Number, Optional, Default: <code>buffer.length</code></li>
</div></ul>
<!--
Decodes and returns a string from buffer data encoded with `encoding`
(defaults to `'utf8'`) beginning at `start` (defaults to `0`) and ending at
`end` (defaults to `buffer.length`).
-->
<p><code>encoding</code> (デフォルトは <code>'utf8'</code>) でエンコードされたバッファデータの
<code>start</code> (デフォルトは <code>0</code>) から <code>end</code> (デフォルトは <code>buffer.length</code>)
までをデコードした文字列を返します。
</p>
<!--
See `buffer.write()` example, above.
-->
<p>上の <code>buffer.write()</code> の例を参照してください。
</p>
<h3>buf.toJSON()<span><a class="mark" href="#buffer_buf_tojson" id="buffer_buf_tojson">#</a></span></h3>
<!--
Returns a JSON-representation of the Buffer instance. `JSON.stringify`
implicitly calls this function when stringifying a Buffer instance.
-->
<p>バッファインスタンスの JSON 表現を返します。
<code>JSON.stringify()</code> は Buffer のインスタンスを文字列化する際に、
この関数を暗黙的に呼び出します。
</p>
<!--
Example:
-->
<p>例:
</p>
<pre><code>var buf = new Buffer('test');
var json = JSON.stringify(buf);
console.log(json);
// '{"type":"Buffer","data":[116,101,115,116]}'
var copy = JSON.parse(json, function(key, value) {
return value && value.type === 'Buffer'
? new Buffer(value.data)
: value;
});
console.log(copy);
// <Buffer 74 65 73 74></code></pre>
<h3>buf[index]<span><a class="mark" href="#buffer_buf_index" id="buffer_buf_index">#</a></span></h3>
<!--type=property-->
<!--name=[index]-->
<!--
Get and set the octet at `index`. The values refer to individual bytes,
so the legal range is between `0x00` and `0xFF` hex or `0` and `255`.
-->
<p><code>index</code> の位置のオクテットを取得および設定します。
その値は個々のバイトを参照するので、妥当な範囲は 16 進の <code>0x00</code> から <code>0xFF</code>
または <code>0</code> から<code>255</code>までの間です。
</p>
<!--
Example: copy an ASCII string into a buffer, one byte at a time:
-->
<p>例: ASCII 文字列を 1 バイトずつバッファにコピーします
</p>
<pre><code>str = "node.js";
buf = new Buffer(str.length);
for (var i = 0; i < str.length ; i++) {
buf[i] = str.charCodeAt(i);
}
console.log(buf);
// node.js</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>
<!--
* `targetBuffer` Buffer object - Buffer to copy into
* `targetStart` Number, Optional, Default: 0
* `sourceStart` Number, Optional, Default: 0
* `sourceEnd` Number, Optional, Default: `buffer.length`
-->
<ul>
<li><code>targetBuffer</code> Buffer object - コピー先の Buffer</li>
<li><code>targetStart</code> Number, Optional, Default: 0</li>
<li><code>sourceStart</code> Number, Optional, Default: 0</li>
<li><code>sourceEnd</code> Number, Optional, Default: <code>buffer.length</code></li>
</ul>
<!--
Does copy between buffers. The source and target regions can be overlapped.
`targetStart` and `sourceStart` default to `0`.
`sourceEnd` defaults to `buffer.length`.
-->
<p>バッファ間でコピーします。
ソースとターゲットの領域は重なっていても構いません。
<code>targetStart</code> と <code>sourceStart</code> のデフォルトは <code>0</code> です。
<code>sourceEnd</code> のデフォルトは <code>buffer.length</code> です。
</p>
<!--
All values passed that are `undefined`/`NaN` or are out of bounds are set equal
to their respective defaults.
-->
<p><code>undefined</code>/<code>NaN</code> またはその他の不正な値が渡された場合は、
それぞれのデフォルトが設定されます。
</p>
<!--
Example: build two Buffers, then copy `buf1` from byte 16 through byte 19
into `buf2`, starting at the 8th byte in `buf2`.
-->
<p>例: バッファを2個作成し、<code>buf1</code> の 16 バイト目から 19 バイト目を、
<code>buf2</code> の 8 バイト目から始まる位置へコピーします。
</p>
<pre><code>buf1 = new Buffer(26);
buf2 = new Buffer(26);
for (var i = 0 ; i < 26 ; i++) {
buf1[i] = i + 97; // 97 is ASCII a
buf2[i] = 33; // ASCII !
}
buf1.copy(buf2, 8, 16, 20);
console.log(buf2.toString('ascii', 0, 25));
// !!!!!!!!qrst!!!!!!!!!!!!!</code></pre>
<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> Number, Optional, Default: 0</li>
<li><code>end</code> Number, Optional, Default: <code>buffer.length</code></li>
</div></ul>
<!--
Returns a new buffer which references the same memory as the old, but offset
and cropped by the `start` (defaults to `0`) and `end` (defaults to
`buffer.length`) indexes. Negative indexes start from the end of the buffer.
-->
<p>元のバッファと同じメモリを参照しますが、<code>start</code> (デフォルトは <code>0</code>) と
<code>end</code> (デフォルトは <code>buffer.length</code>) で示されるオフセットと長さを持つ
新しいバッファを返します。
負のインデックスはバッファの末尾から開始します。
</p>
<!--
**Modifying the new buffer slice will modify memory in the original buffer!**
-->
<p><strong>新しいバッファスライスの変更は、オリジナルバッファのメモリを変更することになります!</strong>
</p>
<!--
Example: build a Buffer with the ASCII alphabet, take a slice, then modify one
byte from the original Buffer.
-->
<p>例: ASCII のアルファベットでバッファを構築してスライスし、元のバッファで 1 バイトを変更します。
</p>
<pre><code>var buf1 = new Buffer(26);
for (var i = 0 ; i < 26 ; i++) {
buf1[i] = i + 97; // 97 is ASCII a
}
var buf2 = buf1.slice(0, 3);
console.log(buf2.toString('ascii', 0, buf2.length));
buf1[0] = 33;
console.log(buf2.toString('ascii', 0, buf2.length));
// abc
// !bc</code></pre>
<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> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
<li>Return: Number</li>
</div></ul>
<!--
Reads an unsigned 8 bit integer from the buffer at the specified offset.
Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer. Defaults to `false`.
-->
<p>バッファの指定された位置を符号無し 8bit 整数として読み込みます。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら <code>offset</code> の検証をスキップします。
これは <code>offset</code> がバッファの終端を越えてしまう場合があることを意味します。
デフォルトは <code>false</code> です。
</p>
<!--
Example:
-->
<p>例:
</p>
<pre><code>var buf = new Buffer(4);
buf[0] = 0x3;
buf[1] = 0x4;
buf[2] = 0x23;
buf[3] = 0x42;
for (ii = 0; ii < buf.length; ii++) {
console.log(buf.readUInt8(ii));
}
// 0x3
// 0x4
// 0x23
// 0x42</code></pre>
<h3>buf.readUInt16LE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readuint16le_offset_noassert" id="buffer_buf_readuint16le_offset_noassert">#</a></span></h3>
<h3>buf.readUInt16BE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readuint16be_offset_noassert" id="buffer_buf_readuint16be_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
<li>Return: Number</li>
</ul>
<!--
Reads an unsigned 16 bit integer from the buffer at the specified offset with
specified endian format.
Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer. Defaults to `false`.
-->
<p>バッファの指定された位置を符号無し 16bit 整数として読み込みます。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら <code>offset</code> の検証をスキップします。
これは <code>offset</code> がバッファの終端を越えてしまう場合があることを意味します。
デフォルトは <code>false</code> です。
</p>
<!--
Example:
-->
<p>例:
</p>
<pre><code>var buf = new Buffer(4);
buf[0] = 0x3;
buf[1] = 0x4;
buf[2] = 0x23;
buf[3] = 0x42;
console.log(buf.readUInt16BE(0));
console.log(buf.readUInt16LE(0));
console.log(buf.readUInt16BE(1));
console.log(buf.readUInt16LE(1));
console.log(buf.readUInt16BE(2));
console.log(buf.readUInt16LE(2));
// 0x0304
// 0x0403
// 0x0423
// 0x2304
// 0x2342
// 0x4223</code></pre>
<h3>buf.readUInt32LE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readuint32le_offset_noassert" id="buffer_buf_readuint32le_offset_noassert">#</a></span></h3>
<h3>buf.readUInt32BE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readuint32be_offset_noassert" id="buffer_buf_readuint32be_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
<li>Return: Number</li>
</ul>
<!--
Reads an unsigned 32 bit integer from the buffer at the specified offset with
specified endian format.
Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer. Defaults to `false`.
-->
<p>バッファの指定された位置を符号無し 32bit 整数として読み込みます。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら <code>offset</code> の検証をスキップします。
これは <code>offset</code> がバッファの終端を越えてしまう場合があることを意味します。
デフォルトは <code>false</code> です。
</p>
<!--
Example:
-->
<p>例:
</p>
<pre><code>var buf = new Buffer(4);
buf[0] = 0x3;
buf[1] = 0x4;
buf[2] = 0x23;
buf[3] = 0x42;
console.log(buf.readUInt32BE(0));
console.log(buf.readUInt32LE(0));
// 0x03042342
// 0x42230403</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> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
<li>Return: Number</li>
</div></ul>
<!--
Reads a signed 8 bit integer from the buffer at the specified offset.
Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer. Defaults to `false`.
Works as `buffer.readUInt8`, except buffer contents are treated as two's
complement signed values.
-->
<p>バッファの指定された位置を符号付き 8bit 整数として読み込みます。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら <code>offset</code> の検証をスキップします。
これは <code>offset</code> がバッファの終端を越えてしまう場合があることを意味します。
デフォルトは <code>false</code> です。
</p>
<p>バッファの内容を 2 の補数による符号付き値として扱うこと以外は
<code>buffer.readUInt8</code> と同じように動作します。
</p>
<h3>buf.readInt16LE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readint16le_offset_noassert" id="buffer_buf_readint16le_offset_noassert">#</a></span></h3>
<h3>buf.readInt16BE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readint16be_offset_noassert" id="buffer_buf_readint16be_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
<li>Return: Number</li>
</ul>
<!--
Reads a signed 16 bit integer from the buffer at the specified offset with
specified endian format.
Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer. Defaults to `false`.
Works as `buffer.readUInt16*`, except buffer contents are treated as two's
complement signed values.
-->
<p>バッファの指定された位置を符号付き 16bit 整数として読み込みます。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら <code>offset</code> の検証をスキップします。
これは <code>offset</code> がバッファの終端を越えてしまう場合があることを意味します。
デフォルトは <code>false</code> です。
</p>
<p>バッファの内容を 2 の補数による符号付き値として扱うこと以外は
<code>buffer.readUInt16</code> と同じように動作します。
</p>
<h3>buf.readInt32LE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readint32le_offset_noassert" id="buffer_buf_readint32le_offset_noassert">#</a></span></h3>
<h3>buf.readInt32BE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readint32be_offset_noassert" id="buffer_buf_readint32be_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
<li>Return: Number</li>
</ul>
<!--
Reads a signed 32 bit integer from the buffer at the specified offset with
specified endian format.
Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer. Defaults to `false`.
Works as `buffer.readUInt32*`, except buffer contents are treated as two's
complement signed values.
-->
<p>バッファの指定された位置を符号付き 32bit 整数として読み込みます。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら <code>offset</code> の検証をスキップします。
これは <code>offset</code> がバッファの終端を越えてしまう場合があることを意味します。
デフォルトは <code>false</code> です。
</p>
<p>バッファの内容を 2 の補数による符号付き値として扱うこと以外は
<code>buffer.readUInt32</code> と同じように動作します。
</p>
<h3>buf.readFloatLE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readfloatle_offset_noassert" id="buffer_buf_readfloatle_offset_noassert">#</a></span></h3>
<h3>buf.readFloatBE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readfloatbe_offset_noassert" id="buffer_buf_readfloatbe_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
<li>Return: Number</li>
</ul>
<!--
Reads a 32 bit float from the buffer at the specified offset with specified
endian format.
Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer. Defaults to `false`.
-->
<p>バッファの指定された位置を 32bit 浮動小数点数として読み込みます。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら <code>offset</code> の検証をスキップします。
これは <code>offset</code> がバッファの終端を越えてしまう場合があることを意味します。
デフォルトは <code>false</code> です。
</p>
<!--
Example:
-->
<p>例:
</p>
<pre><code>var buf = new Buffer(4);
buf[0] = 0x00;
buf[1] = 0x00;
buf[2] = 0x80;
buf[3] = 0x3f;
console.log(buf.readFloatLE(0));
// 0x01</code></pre>
<h3>buf.readDoubleLE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readdoublele_offset_noassert" id="buffer_buf_readdoublele_offset_noassert">#</a></span></h3>
<h3>buf.readDoubleBE(offset, [noAssert])<span><a class="mark" href="#buffer_buf_readdoublebe_offset_noassert" id="buffer_buf_readdoublebe_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
<li>Return: Number</li>
</ul>
<!--
Reads a 64 bit double from the buffer at the specified offset with specified
endian format.
Set `noAssert` to true to skip validation of `offset`. This means that `offset`
may be beyond the end of the buffer. Defaults to `false`.
-->
<p>バッファの指定された位置を 64bit 倍精度浮動小数点数として読み込みます。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら <code>offset</code> の検証をスキップします。
これは <code>offset</code> がバッファの終端を越えてしまう場合があることを意味します。
デフォルトは <code>false</code> です。
</p>
<!--
Example:
-->
<p>例:
</p>
<pre><code>var buf = new Buffer(8);
buf[0] = 0x55;
buf[1] = 0x55;
buf[2] = 0x55;
buf[3] = 0x55;
buf[4] = 0x55;
buf[5] = 0x55;
buf[6] = 0xd5;
buf[7] = 0x3f;
console.log(buf.readDoubleLE(0));
// 0.3333333333333333</code></pre>
<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> Number</li>
<li><code>offset</code> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
</div></ul>
<!--
Writes `value` to the buffer at the specified offset. Note, `value` must be a
valid unsigned 8 bit integer.
Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` 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. Defaults to `false`.
-->
<p><code>value</code> を符号無し 8bit 整数としてバッファの指定された位置に、
指定されたエンディアンで書き込みます。
<code>value</code> は妥当な 8bit 符号無し整数でなければならないことに注意してください。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら,<code>value</code> と <code>offset</code> の検証をスキップします。
これは、<code>value</code> がこの関数で扱えるより大きな場合や、<code>offset</code>
がバッファの終端を越えてしまう場合は、静かに捨てられることを意味します。
正確性に確信がない限り、これらを使用すべきではありません。
デフォルトは <code>false</code> です。
</p>
<!--
Example:
-->
<p>例:
</p>
<pre><code>var buf = new Buffer(4);
buf.writeUInt8(0x3, 0);
buf.writeUInt8(0x4, 1);
buf.writeUInt8(0x23, 2);
buf.writeUInt8(0x42, 3);
console.log(buf);
// <Buffer 03 04 23 42></code></pre>
<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>
<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>
<ul>
<li><code>value</code> Number</li>
<li><code>offset</code> Number</li>
<li><code>noAssert</code> Boolean, Optional, Default: false</li>
</ul>
<!--
Writes `value` to the buffer at the specified offset with specified endian
format. Note, `value` must be a valid unsigned 16 bit integer.
Set `noAssert` to true to skip validation of `value` and `offset`. This means
that `value` may be too large for the specific function and `offset` 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. Defaults to `false`.
-->
<p><code>value</code> を符号無し 16bit 整数としてバッファの指定された位置に、
指定されたエンディアンで書き込みます。
<code>value</code> は妥当な 16bit 符号無し整数でなければならないことに注意してください。
</p>
<p>もし <code>noAssert</code> が <code>true</code> なら,<code>value</code> と <code>offset</code> の検証をスキップします。
これは、<code>value</code> がこの関数で扱えるより大きな場合や、<code>offset</code>
がバッファの終端を越えてしまう場合は、静かに捨てられることを意味します。