blob_JavaScript

miin·2022년 7월 20일
0

Java Script

목록 보기
25/35
post-thumbnail

정의

  • Blob(Binary Large Object, 블랍)은 이미지, 사운드, 비디오와 같은 멀티미디어 데이터를 다룰 때 사용할 수 있다
  • 대개 데이터의 크기(Byte) 및 MIME 타입을 알아내거나, 데이터를 송수신을 위한 작은 Blob 객체로 나누는 등의 작업에 사용한다
  • input type='file'도 name과 lastModifiedDate 속성이 존재하는 Blob 객체이다.

사용

새로운 blob 객체를 반환단다
생성시 인수로 배열과 옵션을 받는다
const newBlob = new Blob(array, options);

array

Blob 생성자의 첫번째 인수로 ArrayBuffer, ArrayBufferView, Blob(File), DOMString 객체 또는 이러한 객체가 혼합된 Array를 사용할 수 있다.

new Blob([new ArrayBuffer(data)], { type: 'video/mp4' });
new Blob(new Uint8Array(data), { type: 'image/png' });  
new Blob(['<div>Hello Blob!</div>'], {
  type: 'text/html',
  endings: 'native'
});

options

옵션으로는 type과 endings를 설정할 수 있다.
type은 데이터의 MIME 타입을 설정하며, 기본값은 "" 이다.
endings는 \n을 포함하는 문자열 처리를 "transparent"와 "native"로 지정할 수 있으며, 기본값은 "transparent"이다.

참고블로그

0개의 댓글