1# ArkTS Subsystem Changelog
2
3## cl.arkts.1 StringDecoder's Incorrect Decoding Behavior in Specific Scenarios Is Changed
4
5**Access Level**
6
7Public API
8
9**Reason for Change**
10
11If the input parameter Uint8Array contains element 0, StringDecoder cannot decode the data following element 0. Instead, it truncates the data at the position of element 0. As such, the decoded data is incomplete.
12
13**Change Impact**
14
15This change is a compatible change.
16
17Before change:
18When the Uint8Array that contains element 0 is encoded, the data is incomplete. Encoding the decoded data fails to restore the original Uint8Array.
19
20After change:
21The Uint8Array that contains element 0 is correctly decoded, and the decoded data is complete.
22
23**Start API Level**
24
2512
26
27**Change Since**
28
29OpenHarmony SDK 5.0.0.43
30
31**Key API/Component Changes**
32
33Two APIs in the util.StringDecoder module:
34
35write(chunk: string | Uint8Array): string;
36
37end(chunk?: string | Uint8Array): string;
38
39**Adaptation Guide**
40
41No adaptation is required.
42
43```ts
44import { util } from '@kit.ArkTS';
45
46let decoder = new util.StringDecoder('utf-8');
47// 0xE4, 0xBD, 0xA0 Decoding result: Hello
48// 0                Decoding result: \u0000 (invisible character, occupying one byte)
49// 0xE5, 0xA5, 0xBD decoding result: World
50let input = new Uint8Array([0xE4, 0xBD, 0xA0, 0, 0xE5, 0xA5, 0xBD]);
51const decoded = decoder.write(input);
52const decodedend = decoder.end(input);
53
54// Before change:
55console.info("decoded:", decoded)); // Hello
56// console.info("decoded.length:", decoded.length); // 1
57// console.info ("decodedend:," decodedend); // Hello
58// console.info("decodedend.length:", decodedend.length); // 1
59
60// Now:
61console.info("decoded:", decoded)); // Hello World
62console.info("decoded.length:", decoded.length); // 3
63console.info("decodedend:", decodedend);// Hello World
64console.info("decodedend.length:", decodedend.length); // 3
65```
66