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/01-arraybuffer-binary-arrays/article.md
+27-25Lines changed: 27 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,62 +187,64 @@ alert(uint8array[1]); // 1
187
187
188
188
## متدهای TypedArray
189
189
190
-
`TypedArray`has regular `Array` methods, with notable exceptions.
190
+
متدهای `TypedArray`مانند آرایههای معمولی میباشد ولی استثناهای قابل توجهی نیز وجود دارد.
191
191
192
-
We can iterate, `map`,`slice`,`find`,`reduce`etc.
192
+
ما میتوانیم `map`،`slice`،`find`،`reduce`و غیره را پیمایش کنیم.
193
193
194
-
There are few things we can't do though:
194
+
هرچند، تعداد کمی کار وجود دارد که ما نمیتوانیم انجام دهیم:
195
195
196
-
- No `splice` -- we can't "delete" a value, because typed arrays are views on a buffer, and these are fixed, contiguous areas ofmemory. All we can do is to assign a zero.
197
-
- No `concat` method.
196
+
- بدون `splice`-- ما نمیتوانیم یک مقدار را "حذف" کنیم، زیرا آرایههای typed، درواقع viewهایی روی یک بافر هستند که ناحیههایی ثابت و پیوسته روی حافظه میباشند. تنها کاری که ما میتوانیم انجام دهیم تخصیص یک صفر است.
198
197
199
-
There are two additional methods:
198
+
- بدون متد `concat`
200
199
201
-
-`arr.set(fromArr, [offset])` copies all elements from `fromArr` to the `arr`, starting at position `offset` (0 by default).
202
-
-`arr.subarray([begin, end])` creates a newviewof the same type from `begin` to `end` (exclusive). That's similar to `slice` method (that's also supported), but doesn't copy anything -- just creates a new view, to operate on the given piece of data.
200
+
دو ممتد اضافی نیز وجود دارد:
203
201
204
-
These methods allow us to copy typed arrays, mix them, create new arrays from existing ones, and so on.
202
+
- متد `arr.set(fromArr, [offset])` تمام اعضای `fromArr` را در `arr` کپی میکند، که این کپی کردن از محل `offset` شروع میشود.(حالت پیشفرض آن 0 است.)
203
+
204
+
- متد `arr.subarray([begin, end])` یک view جدید از همان نوع را از `begin` تا `end` میسازد(انحصاری). این متد مانند متد `slice` است(آن متد نیز پشتیبانی میشود.) ولی چیزی را کپی نمیکند -- فقط یک view جدید میسازد که روی دادههای داده شده، عمملیات انجام دهد.
205
+
206
+
این متدها به ما اجازه میدهد که آرایههای typed را کپی کنیم، آنها را با هم ترکیب کنیم، آرایههای جدید از آرایههای موجود بسازیم، و به همین ترتیب.
205
207
206
208
207
209
208
210
## DataView
209
211
210
-
[DataView](mdn:/JavaScript/Reference/Global_Objects/DataView) is a special super-flexible "untyped" view over `ArrayBuffer`. It allows to access the data on any offset in any format.
212
+
یک [DataView](mdn:/JavaScript/Reference/Global_Objects/DataView) یک view خاص فوقالعاده انعطافپذیر "untyped"روی `ArrayBuffer` است. DataView اجازه میهد که در هر offset و در هر فرمتی به دادهها دسترسی داشته باشیم.
211
213
212
-
- For typed arrays, the constructor dictates what the format is. The whole array is supposed to be uniform. The i-th number is `arr[i]`.
213
-
- With `DataView` we access the data with methods like `.getUint8(i)` or `.getUint16(i)`. We choose the format at method call time instead of the construction time.
214
+
- برای آرایههای typed، سازنده فرمت را مشخص میکند. کل آرایه قرار است یکنواخت باشد. عدد iام، `arr[i]` است.
214
215
215
-
The syntax:
216
+
- با `DataView`، ما با متدهایی مانند `.getUint8(i)` یا `.getUint16(i)` به داده دسترسی پیدا میکنیم. ما فرمت را بجای هنگام ساخت، هنگام فراخوانی متد انتخاب میکنیم.
216
217
218
+
سینتکس:
217
219
```js
218
220
new DataView(buffer, [byteOffset], [byteLength])
219
221
```
220
222
221
-
- **`buffer`** -- the underlying `ArrayBuffer`. Unlike typed arrays, `DataView` doesn't create a buffer on its own. We need to have it ready.
222
-
-**`byteOffset`**--the starting byte position of the view(by default 0).
223
-
-**`byteLength`**--the byte length of the view(by default till the end of`buffer`).
223
+
-**`buffer`**-- بافر مخصوص خودش را نمیسازد. ما باید آن را آماده داشته باشیم typed برخلاف آرایههای `DataView` .دربرگیرنده `ArrayBuffer`
224
+
-**`byteOffset`**--(حالت پیشفرض 0 میباشد)view محل بایت شروعکنندهی
225
+
-**`byteLength`**--(حالت پیشفرض تا انتهای بافر میباشد)view طول بایتهای
224
226
225
-
For instance, here we extract numbers in different formats from the same buffer:
227
+
برای نمونه، در اینجا ما اعداد یک بافر یکسان را در فرمتهای مختلف استخراج کردهایم:
226
228
227
229
```js run
228
-
// binary array of 4 bytes, all have the maximal value 255
230
+
// آرایههای دودویی 4 بایتی، که حداکثر مقدار همهی آنها 255 است
229
231
let buffer = new Uint8Array([255, 255, 255, 255]).buffer;
230
232
231
233
let dataView = new DataView(buffer);
232
234
233
-
// get 8-bit number at offset 0
235
+
// صفر offset دریافت یک عدد 8 بیتی در
234
236
alert( dataView.getUint8(0) ); // 255
235
237
236
-
// now get 16-bit number at offset 0, it consists of 2 bytes, together interpreted as 65535
dataView.setUint32(0, 0); // set 4-byte number to zero, thus setting all bytes to 0
244
+
dataView.setUint32(0, 0); // صفر قرار دادن یک عدد 4 بایتی، در نتیجه همه بایتها را صفر میکنیم
243
245
```
244
246
245
-
`DataView` is great when we store mixed-format data in the same buffer. For example, when we store a sequence ofpairs (16-bit integer, 32-bit float), `DataView`allows to access them easily.
247
+
هنگامی که میخواهیم دادههایی با فرمتهای درهم و برهم را در یک بافر ذخیره کنیم، `DataView` عالی است. به عنوان مثال، هنگامی که دنبالهای از جفتهای(عدد صحیح 16 بیتی، عدد اعشاری 32 بیتی) را ذخیره میکنیم، `DataView`به آسانی اجازه دسترسی به آنها را میدهد.
0 commit comments