Skip to content

Commit b31867f

Browse files
Part 3. 3.3 Blob 번역
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ezn3Dq7aWbVPvWonrUn8YK
1 parent 6f33618 commit b31867f

1 file changed

Lines changed: 81 additions & 81 deletions

File tree

4-binary/03-blob/article.md

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
# Blob
22

3-
`ArrayBuffer` and views are a part of ECMA standard, a part of JavaScript.
3+
`ArrayBuffer`와 뷰(view)는 ECMA 표준의 일부로 자바스크립트에 속합니다.
44

5-
In the browser, there are additional higher-level objects, described in [File API](https://www.w3.org/TR/FileAPI/), in particular `Blob`.
5+
브라우저엔 이보다 더 고수준의 객체가 추가로 존재하는데 [File API](https://www.w3.org/TR/FileAPI/)에 기술되어 있습니다. 그중 하나가 `Blob`입니다.
66

7-
`Blob` consists of an optional string `type` (a MIME-type usually), plus `blobParts` -- a sequence of other `Blob` objects, strings and `BufferSource`.
7+
`Blob`은 옵션 문자열 `type`(주로 MIME 타입)과 `blobParts`(다른 `Blob` 객체·문자열·`BufferSource`의 나열)로 구성됩니다.
88

99
![](blob.svg)
1010

11-
The constructor syntax is:
11+
생성자 문법은 다음과 같습니다.
1212

1313
```js
1414
new Blob(blobParts, options);
1515
```
1616

17-
- **`blobParts`** is an array of `Blob`/`BufferSource`/`String` values.
18-
- **`options`** optional object:
19-
- **`type`** -- `Blob` type, usually MIME-type, e.g. `image/png`,
20-
- **`endings`** -- whether to transform end-of-line to make the `Blob` correspond to current OS newlines (`\r\n` or `\n`). By default `"transparent"` (do nothing), but also can be `"native"` (transform).
17+
- **`blobParts`** -- `Blob`·`BufferSource`·`String` 값을 담은 배열입니다.
18+
- **`options`** -- 옵션 객체입니다.
19+
- **`type`** -- `Blob`의 타입으로 주로 `image/png` 같은 MIME 타입이 들어갑니다.
20+
- **`endings`** -- 줄 바꿈 문자를 현재 OS의 새 줄 문자(`\r\n` 또는 `\n`)에 맞게 변환할지 결정합니다. 기본값은 아무 처리도 하지 않는 `"transparent"`이고 변환을 수행하는 `"native"`로 지정할 수도 있습니다.
2121

22-
For example:
22+
예시를 살펴봅시다.
2323

2424
```js
25-
// create Blob from a string
25+
// 문자열로 Blob을 만듭니다.
2626
let blob = new Blob(["<html>…</html>"], {type: 'text/html'});
27-
// please note: the first argument must be an array [...]
27+
// 첫 번째 인수는 반드시 배열 [...] 형태여야 한다는 점에 유의하세요.
2828
```
2929

3030
```js
31-
// create Blob from a typed array and strings
32-
let hello = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in binary form
31+
// TypedArray와 문자열을 조합해 Blob을 만듭니다.
32+
let hello = new Uint8Array([72, 101, 108, 108, 111]); // 이진 형태의 "Hello"
3333

3434
let blob = new Blob([hello, ' ', 'world'], {type: 'text/plain'});
3535
```
3636

3737

38-
We can extract `Blob` slices with:
38+
`Blob`의 일부를 추출할 땐 다음 메서드를 사용합니다.
3939

4040
```js
4141
blob.slice([byteStart], [byteEnd], [contentType]);
4242
```
4343

44-
- **`byteStart`** -- the starting byte, by default 0.
45-
- **`byteEnd`** -- the last byte (exclusive, by default till the end).
46-
- **`contentType`** -- the `type` of the new blob, by default the same as the source.
44+
- **`byteStart`** -- 시작 바이트로 기본값은 0입니다.
45+
- **`byteEnd`** -- 마지막 바이트입니다(해당 바이트 직전까지 추출하며 기본값은 끝까지).
46+
- **`contentType`** -- 새로 만들 blob의 `type`으로 기본값은 원본과 같습니다.
4747

48-
The arguments are similar to `array.slice`, negative numbers are allowed too.
48+
인수 구성이 `array.slice`와 유사하고 음수도 허용됩니다.
4949

50-
```smart header="`Blob` objects are immutable"
51-
We can't change data directly in a `Blob`, but we can slice parts of a `Blob`, create new `Blob` objects from them, mix them into a new `Blob` and so on.
50+
```smart header="변경할 수 없는 `Blob` 객체"
51+
`Blob` 안의 데이터를 직접 변경할 방법은 없습니다. 대신 `Blob`을 잘라 새로운 `Blob` 객체를 만들고 이를 다른 것과 섞어 또 다른 `Blob`을 만드는 일은 가능합니다.
5252

53-
This behavior is similar to JavaScript strings: we can't change a character in a string, but we can make a new corrected string.
53+
자바스크립트 문자열과 유사한 동작 방식입니다. 문자열 중간의 글자 하나를 고칠 순 없지만 고친 내용을 담은 새 문자열은 만들 수 있죠.
5454
```
5555
56-
## Blob as URL
56+
## Blob을 URL로 사용하기
5757
58-
A Blob can be easily used as an URL for `<a>`, `<img>` or other tags, to show its contents.
58+
Blob은 그 내용을 표시하기 위한 URL로서 `<a>`·`<img>` 등의 태그에 쉽게 사용할 수 있습니다.
5959
60-
Thanks to `type`, we can also download/upload `Blob` objects, and the `type` naturally becomes `Content-Type` in network requests.
60+
`type`이 있는 덕분에 `Blob` 객체를 다운로드·업로드할 수도 있습니다. 네트워크 요청에서 `type`은 자연스럽게 `Content-Type` 헤더가 됩니다.
6161
62-
Let's start with a simple example. By clicking on a link you download a dynamically-generated `Blob` with `hello world` contents as a file:
62+
간단한 예시부터 시작해 봅시다. 링크를 클릭하면 동적으로 생성된 `hello world` 내용의 `Blob`이 파일로 다운로드됩니다.
6363
6464
```html run
65-
<!-- download attribute forces the browser to download instead of navigating -->
66-
<a download="hello.txt" href='#' id="link">Download</a>
65+
<!-- download 속성이 있으면 브라우저는 링크 이동 대신 다운로드를 수행합니다. -->
66+
<a download="hello.txt" href='#' id="link">다운로드</a>
6767
6868
<script>
6969
let blob = new Blob(["Hello, world!"], {type: 'text/plain'});
@@ -72,9 +72,9 @@ link.href = URL.createObjectURL(blob);
7272
</script>
7373
```
7474

75-
We can also create a link dynamically in JavaScript and simulate a click by `link.click()`, then download starts automatically.
75+
자바스크립트에서 링크를 동적으로 만들고 `link.click()`으로 클릭을 시뮬레이션할 수도 있습니다. 이러면 사용자 조작 없이 다운로드가 자동으로 시작됩니다.
7676

77-
Here's the similar code that causes user to download the dynamicallly created `Blob`, without any HTML:
77+
HTML 없이 동적으로 생성한 `Blob`을 다운로드하게 만드는 비슷한 코드입니다.
7878

7979
```js run
8080
let link = document.createElement('a');
@@ -89,50 +89,50 @@ link.click();
8989
URL.revokeObjectURL(link.href);
9090
```
9191

92-
`URL.createObjectURL` takes a `Blob` and creates a unique URL for it, in the form `blob:<origin>/<uuid>`.
92+
`URL.createObjectURL``Blob`을 받아 `blob:<origin>/<uuid>` 형태의 고유한 URL을 만듭니다.
9393

94-
That's what the value of `link.href` looks like:
94+
`link.href` 값은 다음과 같은 모습입니다.
9595

9696
```
9797
blob:https://javascript.info/1e67e00e-860d-40a5-89ae-6ab0cbee6273
9898
```
9999

100-
For each URL generated by `URL.createObjectURL` the browser stores a URL -> `Blob` mapping internally. So such URLs are short, but allow to access the `Blob`.
100+
브라우저는 `URL.createObjectURL`로 생성한 URL마다 URL `Blob` 매핑을 내부에 저장합니다. 그래서 URL이 짧아도 이 URL로 `Blob`에 접근할 수 있습니다.
101101

102-
A generated URL (and hence the link with it) is only valid within the current document, while it's open. And it allows to reference the `Blob` in `<img>`, `<a>`, basically any other object that expects an url.
102+
생성된 URL(과 그 URL을 쓰는 링크)은 현재 문서가 열려 있는 동안 그 문서 안에서만 유효합니다. 이 URL은 `<img>`·`<a>`를 비롯해 URL을 기대하는 모든 객체에서 `Blob`을 참조하는 데 쓸 수 있습니다.
103103

104-
There's a side-effect though. While there's a mapping for a `Blob`, the `Blob` itself resides in the memory. The browser can't free it.
104+
다만 부작용이 하나 있습니다. `Blob` 매핑이 존재하는 동안엔 `Blob` 자체가 메모리에 상주합니다. 브라우저가 이를 해제할 수 없습니다.
105105

106-
The mapping is automatically cleared on document unload, so `Blob` objects are freed then. But if an app is long-living, then that doesn't happen soon.
106+
매핑은 문서가 언로드될 때 자동으로 정리되고 그때 `Blob` 객체도 함께 해제됩니다. 하지만 앱이 오래 살아 있다면 해제 시점은 금방 오지 않습니다.
107107

108-
**So if we create a URL, that `Blob` will hang in memory, even if not needed any more.**
108+
**따라서 URL을 만들어 두면 그 `Blob`은 더는 필요 없어져도 메모리에 남아 있게 됩니다.**
109109

110-
`URL.revokeObjectURL(url)` removes the reference from the internal mapping, thus allowing the `Blob` to be deleted (if there are no other references), and the memory to be freed.
110+
`URL.revokeObjectURL(url)`은 내부 매핑에서 참조를 제거합니다. 그 덕분에(다른 참조가 없다면) `Blob`이 삭제될 수 있고 메모리도 해제됩니다.
111111

112-
In the last example, we intend the `Blob` to be used only once, for instant downloading, so we call `URL.revokeObjectURL(link.href)` immediately.
112+
마지막 예시에선 `Blob`을 즉시 다운로드에 한 번만 쓸 생각이므로 `URL.revokeObjectURL(link.href)`를 바로 호출했습니다.
113113

114-
In the previous example with the clickable HTML-link, we don't call `URL.revokeObjectURL(link.href)`, because that would make the `Blob` url invalid. After the revocation, as the mapping is removed, the URL doesn't work any more.
114+
클릭 가능한 HTML 링크를 쓴 이전 예시에선 `URL.revokeObjectURL(link.href)`를 호출하지 않습니다. 호출하면 `Blob` URL이 무효가 되기 때문입니다. 취소 후엔 매핑이 제거되어 URL이 더는 동작하지 않습니다.
115115

116-
## Blob to base64
116+
## Blob을 base64로 변환하기
117117

118-
An alternative to `URL.createObjectURL` is to convert a `Blob` into a base64-encoded string.
118+
`URL.createObjectURL`의 대안으로 `Blob`을 base64 인코딩 문자열로 변환하는 방법이 있습니다.
119119

120-
That encoding represents binary data as a string of ultra-safe "readable" characters with ASCII-codes from 0 to 64. And what's more important -- we can use this encoding in "data-urls".
120+
base64 인코딩은 이진 데이터를 0부터 64까지의 ASCII 코드로 이루어진 아주 안전한 '읽을 수 있는' 문자열로 표현합니다. 더 중요한 점은 이 인코딩을 '데이터 URL(data url)'에 쓸 수 있다는 사실입니다.
121121

122-
A [data url](mdn:/http/Data_URIs) has the form `data:[<mediatype>][;base64],<data>`. We can use such urls everywhere, on par with "regular" urls.
122+
[데이터 URL](mdn:/http/Data_URIs)`data:[<mediatype>][;base64],<data>` 형태입니다. 이런 URL은 '일반' URL과 동등하게 어디에서나 사용할 수 있습니다.
123123

124-
For instance, here's a smiley:
124+
웃는 얼굴 이미지를 예시로 살펴봅시다.
125125

126126
```html
127127
<img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7">
128128
```
129129

130-
The browser will decode the string and show the image: <img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7">
130+
브라우저가 문자열을 디코딩해 이미지를 표시합니다. <img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7">
131131

132132

133-
To transform a `Blob` into base64, we'll use the built-in `FileReader` object. It can read data from Blobs in multiple formats. In the [next chapter](info:file) we'll cover it more in-depth.
133+
`Blob`을 base64로 변환할 땐 내장 객체 `FileReader`를 사용합니다. `FileReader`는 Blob의 데이터를 여러 형식으로 읽을 수 있습니다. [다음 챕터](info:file)에서 더 자세히 다루겠습니다.
134134

135-
Here's the demo of downloading a blob, now via base-64:
135+
이번엔 base64를 이용해 blob을 다운로드하는 데모입니다.
136136

137137
```js run
138138
let link = document.createElement('a');
@@ -142,79 +142,79 @@ let blob = new Blob(['Hello, world!'], {type: 'text/plain'});
142142

143143
*!*
144144
let reader = new FileReader();
145-
reader.readAsDataURL(blob); // converts the blob to base64 and calls onload
145+
reader.readAsDataURL(blob); // blob을 base64로 변환하고 변환이 끝나면 onload를 호출합니다.
146146
*/!*
147147

148148
reader.onload = function() {
149-
link.href = reader.result; // data url
149+
link.href = reader.result; // 데이터 URL
150150
link.click();
151151
};
152152
```
153153

154-
Both ways of making an URL of a `Blob` are usable. But usually `URL.createObjectURL(blob)` is simpler and faster.
154+
`Blob`으로 URL을 만드는 두 방법 모두 사용할 수 있습니다. 하지만 보통은 `URL.createObjectURL(blob)`이 더 간단하고 빠릅니다.
155155

156-
```compare title-plus="URL.createObjectURL(blob)" title-minus="Blob to data url"
157-
+ We need to revoke them if care about memory.
158-
+ Direct access to blob, no "encoding/decoding"
159-
- No need to revoke anything.
160-
- Performance and memory losses on big `Blob` objects for encoding.
156+
```compare title-plus="URL.createObjectURL(blob)" title-minus="Blob을 데이터 URL로 변환"
157+
+ 메모리를 신경 쓴다면 URL을 취소해야 합니다.
158+
+ blob에 바로 접근하므로 '인코딩·디코딩'이 없습니다.
159+
- 아무것도 취소할 필요가 없습니다.
160+
- 큰 `Blob` 객체를 인코딩할 때 성능과 메모리 손실이 있습니다.
161161
```
162162

163-
## Image to blob
163+
## 이미지를 Blob으로 변환하기
164164

165-
We can create a `Blob` of an image, an image part, or even make a page screenshot. That's handy to upload it somewhere.
165+
이미지 전체나 일부, 심지어 페이지 스크린샷으로도 `Blob`을 만들 수 있습니다. 만든 `Blob`은 어딘가에 업로드할 때 유용합니다.
166166

167-
Image operations are done via `<canvas>` element:
167+
이미지 연산은 `<canvas>` 요소에서 이뤄집니다.
168168

169-
1. Draw an image (or its part) on canvas using [canvas.drawImage](mdn:/api/CanvasRenderingContext2D/drawImage).
170-
2. Call canvas method [.toBlob(callback, format, quality)](mdn:/api/HTMLCanvasElement/toBlob) that creates a `Blob` and runs `callback` with it when done.
169+
1. [canvas.drawImage](mdn:/api/CanvasRenderingContext2D/drawImage)를 사용해 캔버스에 이미지(또는 이미지 일부)를 그립니다.
170+
2. 캔버스 메서드 [.toBlob(callback, format, quality)](mdn:/api/HTMLCanvasElement/toBlob)를 호출하면 `Blob`이 만들어지고 완성되는 시점에 `callback`이 호출됩니다.
171171

172-
In the example below, an image is just copied, but we could cut from it, or transform it on canvas prior to making a blob:
172+
아래 예시에선 이미지를 복사하기만 하지만 blob으로 만들기 전에 캔버스에서 이미지를 잘라내거나 변형할 수도 있습니다.
173173

174174
```js run
175-
// take any image
175+
// 아무 이미지나 가져옵니다.
176176
let img = document.querySelector('img');
177177

178-
// make <canvas> of the same size
178+
// 이미지와 같은 크기로 <canvas>를 만듭니다.
179179
let canvas = document.createElement('canvas');
180180
canvas.width = img.clientWidth;
181181
canvas.height = img.clientHeight;
182182

183183
let context = canvas.getContext('2d');
184184

185-
// copy image to it (this method allows to cut image)
185+
// 캔버스에 이미지를 복사합니다(drawImage로는 이미지를 잘라낼 수도 있습니다).
186186
context.drawImage(img, 0, 0);
187-
// we can context.rotate(), and do many other things on canvas
187+
// context.rotate()를 비롯해 캔버스에서 다양한 작업을 할 수 있습니다.
188188

189-
// toBlob is async opereation, callback is called when done
189+
// toBlob은 비동기 연산이라 작업이 끝나면 콜백이 호출됩니다.
190190
canvas.toBlob(function(blob) {
191-
// blob ready, download it
191+
// blob이 준비되었으니 다운로드합니다.
192192
let link = document.createElement('a');
193193
link.download = 'example.png';
194194

195195
link.href = URL.createObjectURL(blob);
196196
link.click();
197197

198-
// delete the internal blob reference, to let the browser clear memory from it
198+
// 내부 blob 참조를 삭제해 브라우저가 메모리를 해제할 수 있게 합니다.
199199
URL.revokeObjectURL(link.href);
200200
}, 'image/png');
201201
```
202202

203-
If we prefer `async/await` instead of callbacks:
203+
콜백 대신 `async/await`를 선호한다면 다음처럼 쓸 수 있습니다.
204204
```js
205205
let blob = await new Promise(resolve => canvasElem.toBlob(resolve, 'image/png'));
206206
```
207207

208-
For screenshotting a page, we can use a library such as <https://github.com/niklasvh/html2canvas>. What it does is just walks the page and draws it on `<canvas>`. Then we can get a `Blob` of it the same way as above.
208+
페이지 스크린샷엔 <https://github.com/niklasvh/html2canvas> 같은 라이브러리를 사용할 수 있습니다. 이 라이브러리는 페이지를 훑으며 `<canvas>`에 그대로 그려줄 뿐입니다. 그다음은 위와 같은 방법으로 `Blob`을 얻으면 됩니다.
209209

210-
## From Blob to ArrayBuffer
210+
## Blob에서 ArrayBuffer 추출하기
211211

212-
The `Blob` constructor allows to create a blob from almost anything, including any `BufferSource`.
212+
`Blob` 생성자를 사용하면 `BufferSource`를 포함해 거의 모든 것으로 blob을 만들 수 있습니다.
213213

214-
But if we need to perform low-level processing, we can get the lowest-level `ArrayBuffer` from it using `FileReader`:
214+
반대로 저수준 처리가 필요하다면 `FileReader`를 사용해 blob에서 가장 저수준 형태인 `ArrayBuffer`를 얻을 수 있습니다.
215215

216216
```js
217-
// get arrayBuffer from blob
217+
// blob에서 arrayBuffer를 얻습니다.
218218
let fileReader = new FileReader();
219219

220220
*!*
@@ -227,15 +227,15 @@ fileReader.onload = function(event) {
227227
```
228228

229229

230-
## Summary
230+
## 요약
231231

232-
While `ArrayBuffer`, `Uint8Array` and other `BufferSource` are "binary data", a [Blob](https://www.w3.org/TR/FileAPI/#dfn-Blob) represents "binary data with type".
232+
`ArrayBuffer`·`Uint8Array` 등의 `BufferSource`가 '이진 데이터'라면 [Blob](https://www.w3.org/TR/FileAPI/#dfn-Blob)은 '타입이 있는 이진 데이터'를 나타냅니다.
233233

234-
That makes Blobs convenient for upload/download operations, that are so common in the browser.
234+
그 덕분에 Blob은 브라우저에서 아주 흔한 업로드·다운로드 작업에 편리하게 쓰입니다.
235235

236-
Methods that perform web-requests, such as [XMLHttpRequest](info:xmlhttprequest), [fetch](info:fetch) and so on, can work with `Blob` natively, as well as with other binary types.
236+
[XMLHttpRequest](info:xmlhttprequest)·[fetch](info:fetch) 등 웹 요청을 수행하는 메서드는 다른 이진 타입과 마찬가지로 `Blob`도 기본으로 다룰 수 있습니다.
237237

238-
We can easily convert betweeen `Blob` and low-level binary data types:
238+
`Blob`과 저수준 이진 데이터 타입 사이의 변환도 간단합니다.
239239

240-
- We can make a Blob from a typed array using `new Blob(...)` constructor.
241-
- We can get back `ArrayBuffer` from a Blob using `FileReader`, and then create a view over it for low-level binary processing.
240+
- `new Blob(...)` 생성자를 사용하면 TypedArray로 Blob을 만들 수 있습니다.
241+
- `FileReader`를 사용하면 Blob에서 `ArrayBuffer`를 다시 얻을 수 있고 그 위에 뷰를 만들어 저수준 이진 처리를 할 수 있습니다.

0 commit comments

Comments
 (0)