Skip to content

Commit dea9ce1

Browse files
committed
v2.4.2(1)
1 parent 0a4467e commit dea9ce1

File tree

2 files changed

+96
-96
lines changed

2 files changed

+96
-96
lines changed
Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,192 +1,192 @@
11
# Data
22

3-
`Data` 类用于表示二进制数据,提供多种方法用于数据的创建、转换、压缩、解压、拼接、读取等操作。可用于处理图像、文件、音频、编码数据等各种原始字节数据。
3+
The `Data` class represents binary data in memory and provides a wide range of methods for manipulating, converting, compressing, decompressing, and transforming that data. It is useful for working with raw byte buffers, encoded files, images, and more.
44

55
---
66

7-
## CompressionAlgorithm(压缩算法枚举)
7+
## CompressionAlgorithm (Enum)
88

9-
该枚举用于指定 `Data` 的压缩或解压算法:
9+
Specifies which compression algorithm to use when compressing or decompressing a `Data` instance:
1010

11-
| 枚举值 | 描述 |
12-
| ------- | --------------------- |
13-
| `lzfse` | LZFSE 压缩算法,快速且高效。 |
14-
| `lz4` | LZ4 压缩算法,压缩和解压速度极快。 |
15-
| `lzma` | LZMA 算法,压缩率高,压缩速度较慢。 |
16-
| `zlib` | Zlib 算法,通用且广泛支持的压缩格式。 |
11+
| Value | Description |
12+
| ------- | --------------------------------------------------------- |
13+
| `lzfse` | Fast and efficient compression using the LZFSE algorithm. |
14+
| `lz4` | Very fast compression with moderate compression ratio. |
15+
| `lzma` | High compression ratio, slower performance. |
16+
| `zlib` | Standard and widely-used compression format. |
1717

1818
---
1919

20-
## 实例属性与方法
20+
## Instance Properties and Methods
2121

2222
### `size: number`
2323

24-
当前数据的字节长度(只读属性)。
24+
The length of the data in bytes (read-only).
2525

2626
---
2727

2828
### `resetBytes(startIndex: number, endIndex: number): void`
2929

30-
将数据中指定范围内的字节清零。
30+
Resets a range of bytes to zero.
3131

32-
* `startIndex`:起始索引(包含)
33-
* `endIndex`:结束索引(不包含)
32+
* `startIndex`: Starting index (inclusive)
33+
* `endIndex`: Ending index (exclusive)
3434

35-
若索引超出范围将抛出异常。
35+
Throws an error if the indices are out of bounds.
3636

3737
---
3838

3939
### `advanced(amount: number): Data`
4040

41-
返回一个新的 `Data` 实例,去除前 `amount` 个字节。
41+
Returns a new `Data` instance by removing the first `amount` bytes from the buffer.
4242

4343
---
4444

4545
### `replaceSubrange(startIndex, endIndex, data): void`
4646

47-
将当前数据中指定范围的字节替换为另一个 `Data` 实例的数据。
47+
Replaces a specified byte range with the content of another `Data` instance.
4848

4949
---
5050

5151
### `compressed(algorithm: CompressionAlgorithm): Data`
5252

53-
使用指定的压缩算法压缩当前数据,返回压缩后的新 `Data` 实例。
53+
Compresses the current data using the specified algorithm and returns a new `Data` instance.
5454

55-
如果数据为空或无法压缩将抛出异常。
55+
Throws an error if the data is empty or cannot be compressed.
5656

5757
---
5858

5959
### `decompressed(algorithm: CompressionAlgorithm): Data`
6060

61-
使用指定的算法对当前数据进行解压,返回解压后的 `Data` 实例。
61+
Decompresses the current data using the specified algorithm and returns a new `Data` instance.
6262

63-
压缩与解压时使用的算法必须一致。
63+
Must use the same algorithm that was used to compress the data.
6464

6565
---
6666

6767
### `slice(start?: number, end?: number): Data`
6868

69-
返回数据的子集片段,形成新的 `Data` 实例。
69+
Returns a new `Data` instance representing a slice of the original.
7070

71-
* `start`:起始索引(默认 0)
72-
* `end`:结束索引(默认到末尾)
71+
* `start`: Starting index (default is `0`)
72+
* `end`: Ending index (default is the end of the data)
7373

7474
---
7575

7676
### `append(other: Data): void`
7777

78-
将另一个 `Data` 实例的数据追加到当前数据末尾。
78+
Appends another `Data` instance to the end of the current one.
7979

8080
---
8181

82-
### `getBytes(): Uint8Array | null`(已废弃)
82+
### `getBytes(): Uint8Array | null` (Deprecated)
8383

84-
请改用 `toUint8Array()`
84+
Use `toUint8Array()` instead.
8585

8686
---
8787

8888
### `toUint8Array(): Uint8Array | null`
8989

90-
将数据转换为 `Uint8Array`
90+
Converts the data into a `Uint8Array`.
9191

9292
---
9393

9494
### `toArrayBuffer(): ArrayBuffer`
9595

96-
将数据转换为 `ArrayBuffer`
96+
Converts the data into an `ArrayBuffer`.
9797

9898
---
9999

100100
### `toBase64String(): string`
101101

102-
将数据编码为 Base64 字符串。
102+
Returns a Base64-encoded string representation of the data.
103103

104104
---
105105

106106
### `toHexString(): string`
107107

108-
将数据编码为十六进制字符串。
108+
Returns a hexadecimal string representation of the data.
109109

110110
---
111111

112112
### `toRawString(encoding?: string): string | null`
113113

114-
将数据转换为字符串,支持指定编码(默认 `"utf-8"`)。
114+
Converts the data into a string using the specified encoding (default: `"utf-8"`).
115115

116116
---
117117

118118
### `toIntArray(): number[]`
119119

120-
将数据转换为由整数表示的字节数组。
120+
Returns an array of integers representing the bytes of the data.
121121

122122
---
123123

124-
## 静态方法
124+
## Static Methods
125125

126126
### `Data.fromIntArray(array: number[]): Data`
127127

128-
从整数数组创建 `Data` 实例。
128+
Creates a `Data` instance from an array of integers.
129129

130130
---
131131

132-
### `Data.fromString(str: string, encoding?: string): Data | null`(已废弃)
132+
### `Data.fromString(str: string, encoding?: string): Data | null` (Deprecated)
133133

134-
请使用 `Data.fromRawString()` 代替。
134+
Use `Data.fromRawString()` instead.
135135

136136
---
137137

138138
### `Data.fromRawString(str: string, encoding?: string): Data | null`
139139

140-
从字符串创建 `Data` 实例,支持指定编码(默认 `"utf-8"`)。
140+
Creates a `Data` instance from a raw string, using the specified encoding (default: `"utf-8"`).
141141

142142
---
143143

144144
### `Data.fromFile(filePath: string): Data | null`
145145

146-
从本地文件路径读取数据,返回 `Data` 实例。
146+
Reads binary data from a file path and returns a `Data` instance.
147147

148148
---
149149

150150
### `Data.fromArrayBuffer(buffer: ArrayBuffer): Data | null`
151151

152-
`ArrayBuffer` 创建 `Data` 实例。
152+
Creates a `Data` instance from an `ArrayBuffer`.
153153

154154
---
155155

156156
### `Data.fromUint8Array(bytes: Uint8Array): Data | null`
157157

158-
`Uint8Array` 创建 `Data` 实例。
158+
Creates a `Data` instance from a `Uint8Array`.
159159

160160
---
161161

162162
### `Data.fromBase64String(base64: string): Data | null`
163163

164-
从 Base64 编码字符串创建 `Data` 实例。
164+
Creates a `Data` instance from a Base64-encoded string.
165165

166166
---
167167

168168
### `Data.fromHexString(hex: string): Data | null`
169169

170-
从十六进制字符串创建 `Data` 实例。
170+
Creates a `Data` instance from a hexadecimal string.
171171

172172
---
173173

174174
### `Data.fromJPEG(image: UIImage, compressionQuality?: number): Data | null`
175175

176-
将图像转为 JPEG 格式的 `Data` 实例。
176+
Converts a `UIImage` to JPEG format data.
177177

178-
* `compressionQuality`:JPEG 压缩质量,范围 0.0 ~ 1.0,默认值为 1.0(最高质量)
178+
* `compressionQuality`: Compression quality between `0.0` and `1.0` (default: `1.0`)
179179

180180
---
181181

182182
### `Data.fromPNG(image: UIImage): Data | null`
183183

184-
将图像转为 PNG 格式的 `Data` 实例。
184+
Converts a `UIImage` to PNG format data.
185185

186186
---
187187

188188
### `Data.combine(dataList: Data[]): Data`
189189

190-
将多个 `Data` 实例合并为一个新实例。
190+
Combines multiple `Data` instances into one.
191191

192-
如果列表为空或所有数据为空,则返回空数据。
192+
Returns `null` if the list is empty or all items are empty.

0 commit comments

Comments
 (0)