You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 4-binary/02-text-decoder/article.md
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,30 @@
1
-
# TextDecoder and TextEncoder
1
+
# TextDecoder e TextEncoder
2
2
3
-
What if the binary data is actually a string? For instance, we received a file with textual data.
3
+
E se il dato binario in realtà fosse una stringa? Ad esempio, se ricevessimo un file contente dati testuali.
4
4
5
-
The build-in[TextDecoder](https://encoding.spec.whatwg.org/#interface-textdecoder) object allows to read the value into an actual JavaScript string, given the buffer and the encoding.
5
+
L'oggetto integrato[TextDecoder](https://encoding.spec.whatwg.org/#interface-textdecoder), dato il buffer e l'encoding, ci consente di leggere il valore come se fosse una stringa JavaScript.
6
6
7
-
We first need to create it:
7
+
Come prima cosa dobbiamo crearlo:
8
8
```js
9
9
let decoder =newTextDecoder([label], [options]);
10
10
```
11
11
12
-
-**`label`** -- the encoding, `utf-8` by default, but `big5`, `windows-1251`and many other are also supported.
13
-
-**`options`** -- optional object:
14
-
-**`fatal`** -- boolean, if `true`then throw an exception for invalid (non-decodable) characters, otherwise (default) replace them with character`\uFFFD`.
-**`label`**, l'encoding di default è `utf-8`, ma sono supportati anche `big5`, `windows-1251`e molti altri.
13
+
-**`options`**, oggetto opzionale:
14
+
-**`fatal`**, boolean, se vale `true`allora verrà generata un'eccezione per i caratteri invalidi (non-decodificabili), altrimenti (default) verranno rimpiazzati con il carattere`\uFFFD`.
15
+
-**`ignoreBOM`**, boolean, se vale `true`allora ignora BOM (un marcatore opzionale di byte-order Unicode), raramente utilizzato.
16
16
17
-
...And then decode:
17
+
...E successivamente decodificare:
18
18
19
19
```js
20
20
let str =decoder.decode([input], [options]);
21
21
```
22
22
23
-
-**`input`** --`BufferSource`to decode.
24
-
-**`options`** -- optional object:
25
-
-**`stream`** -- true for decoding streams, when`decoder`is called repeatedly with incoming chunks of data. In that case a multi-byte character may occasionally split between chunks. This options tells `TextDecoder`to memorize "unfinished" characters and decode them when the next chunk comes.
23
+
-**`input`**, il`BufferSource`da decodificare.
24
+
-**`options`**, oggetto opzionale:
25
+
-**`stream`**, `true` per la decodifica di stream, quando`decoder`viene invocato ripetutamente con blocchi di dati in arrivo. In questo caso un carattere multi-byte potrebbe venir diviso in blocchi. Questa opzione dice al `TextDecoder`di memorizzare i caratteri "incompleti" e di decodificarli all'arrivo del prossimo blocco.
26
26
27
-
For instance:
27
+
Ad esempio:
28
28
29
29
```js run
30
30
let uint8Array =newUint8Array([72, 101, 108, 108, 111]);
@@ -39,34 +39,34 @@ let uint8Array = new Uint8Array([228, 189, 160, 229, 165, 189]);
0 commit comments