|
1 | | -# ArrayBuffer, binary arrays |
| 1 | +# ArrayBuffer، آرایه دودویی |
2 | 2 |
|
3 | | -In web-development we meet binary data mostly while dealing with files (create, upload, download). Another typical use case is image processing. |
| 3 | +در توسعهی وب ما معمولا هنگام سروکار داشتن با فایلها(ساختن، بارگذاری کردن، دانلود کردن) به دادههای دودویی برخورد میکنیم. یکی دیگر از استفادههای رایج آن پردازش تصویر میباشد. |
4 | 4 |
|
5 | | -That's all possible in JavaScript, and binary operations are high-performant. |
| 5 | +همهی اینها در جاوااسکریپت ممکن است، و عملیاتهای دودویی عملکرد بالایی دارند. |
6 | 6 |
|
7 | | -Although, there's a bit of confusion, because there are many classes. To name a few: |
| 7 | +هرچند، اندکی احتمال اشتباه کردن وجود دارد، زیرا کلاسهای بسیاری وجود دارند. برخی از آنها عبارتند از: |
8 | 8 | - `ArrayBuffer`, `Uint8Array`, `DataView`, `Blob`, `File`, etc. |
9 | 9 |
|
10 | | -Binary data in JavaScript is implemented in a non-standard way, compared to other languages. But when we sort things out, everything becomes fairly simple. |
| 10 | +دادههای دودویی در جاوااسکریپت، نسبت به سایر زبانها به شکل غیراستانداردی پیادهسازی شدهاند. ولی هنگاهی که ما چیزها را مرتب میکنیم، همه چیز نسبتا ساده میشود. |
11 | 11 |
|
12 | | -**The basic binary object is `ArrayBuffer` -- a reference to a fixed-length contiguous memory area.** |
| 12 | +**شی دودویی پایه `ArrayBuffer` است -- یک اشاره به یک ناحیهی پیوستهی حافظه با طول ثابت.** |
13 | 13 |
|
14 | | -We create it like this: |
| 14 | +آن را به شکل زیر میسازیم: |
15 | 15 | ```js run |
16 | | -let buffer = new ArrayBuffer(16); // create a buffer of length 16 |
| 16 | +let buffer = new ArrayBuffer(16); // ساخت یک بافر با طول 16 |
17 | 17 | alert(buffer.byteLength); // 16 |
18 | 18 | ``` |
19 | 19 |
|
20 | | -This allocates a contiguous memory area of 16 bytes and pre-fills it with zeroes. |
| 20 | +این کد یک حافظهی پیوسته به اندازه 16 بایت را اختصاص میدهد و آن را با صفر مقداردهی اولیه میکند. |
21 | 21 |
|
22 | | -```warn header="`ArrayBuffer` is not an array of something" |
23 | | -Let's eliminate a possible source of confusion. `ArrayBuffer` has nothing in common with `Array`: |
24 | | -- It has a fixed length, we can't increase or decrease it. |
25 | | -- It takes exactly that much space in the memory. |
26 | | -- To access individual bytes, another "view" object is needed, not `buffer[index]`. |
| 22 | +```هدر هشدار="`ArrayBuffer` یک آرایه از چیزی نیست." بیایید یک منبع احتمال اشتباه کردن را رفع کنیم. `ArrayBuffer` هیچ ارتباطی با آرایه ندارد: |
| 23 | +- یک طول ثابت دارد، ما نمیتوانیم آن را کم یا زیاد کنیم. |
| 24 | +- دقیقا به همان میزان حافظه اشغال میکند. |
| 25 | +- برای دسترسی به بایتهای جداگانه، یک شی "View" دیگر لازم است، نه `buffer[index]`. |
27 | 26 | ``` |
28 | 27 |
|
29 | | -`ArrayBuffer` is a memory area. What's stored in it? It has no clue. Just a raw sequence of bytes. |
30 | | -
|
31 | | -**To manipulate an `ArrayBuffer`, we need to use a "view" object.** |
| 28 | +یک ناحیه از حافظه است. چه چیزی در آن ذخیره میشود؟ هیچ سرنخی وجود ندارد. فقط یک دنباله خالی از بایتها`ArrayBuffer`. |
32 | 29 |
|
| 30 | +**برای دستکاری کردن یک `ArrayBuffer`، ما باید از یک شی "View" استفاده کنیم.** |
33 | 31 | A view object does not store anything on its own. It's the "eyeglasses" that give an interpretation of the bytes stored in the `ArrayBuffer`. |
34 | 32 |
|
35 | 33 | For instance: |
|
0 commit comments