blob: 4dfef08d021bd8d54eb87c17ad3f82e9b1976ca2 (
plain)
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
|
---
title: Blob.text()
slug: Web/API/Blob/text
tags:
- API
- Blob
- File API
- Method
- Reference
- String
- Text
- Utf-8
- get
- read
translation_of: Web/API/Blob/text
---
<div>{{APIRef("File API")}}</div>
<p><span class="seoSummary">{{domxref("Blob")}} インターフェイスの <code><strong>text()</strong></code> メソッドは {{jsxref("Promise")}} を返しますが、それは Blob の内容を含む文字列で解決され、UTF-8 として解釈されます。</span></p>
<ul>
</ul>
<h2 id="シンタックス">シンタックス</h2>
<pre class="syntaxbox notranslate">var <em>textPromise</em> = <em>blob</em>.text();
<em>blob</em>.text().then(<em>text</em> => /* テキストに対して処理をする */);
var <em>text</em> = await <em>blob</em>.text();
</pre>
<h3 id="パラメータ">パラメータ</h3>
<p>なし</p>
<h3 id="戻り値">戻り値</h3>
<p>Blob のデータをテキスト文字列として含む {{domxref("USVString")}} で解決する Promise。データは<em>常に</em> UTF-8 形式であると推定されます。</p>
<h2 id="使用上のメモ">使用上のメモ</h2>
<p>{{domxref("FileReader")}} メソッド {{domxref("FileReader.readAsText", "readAsText()")}} は、同様の機能を実行する古いメソッドです。これは、<code>Blob</code> と {{domxref("File")}} オブジェクトの両方で動作します。主な違いは2つあります。</p>
<ul>
<li><code>Blob.text()</code> が Promise を返すのに対し、<code>FileReader.readAsText()</code> はイベントベースの API です</li>
<li><code>Blob.text()</code> は常にエンコーディングとして UTF-8 を使用しますが、<code>FileReader.readAsText()</code> は Blob のタイプと指定されたエンコーディング名に応じて異なるエンコーディングを使用することができます</li>
</ul>
<h2 id="仕様">仕様</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">仕様書</th>
<th scope="col">ステータス</th>
<th scope="col">コメント</th>
</tr>
<tr>
<td>{{SpecName("File API", "#dom-blob-text", "Blob.text()")}}</td>
<td>{{Spec2("File API")}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="ブラウザの互換性">ブラウザの互換性</h2>
<p>{{Compat("api.Blob.text")}}</p>
<h2 id="あわせて参照">あわせて参照</h2>
<ul>
<li>{{domxref("Body.text()")}}</li>
<li><a href="/ja/docs/Web/API/Streams_API">Streams API</a></li>
<li>{{domxref("FileReader.readAsText()")}}</li>
</ul>
|