아래 코드를 사용하여 JavaScript에 두 개의 blob 파일을로드합니다.JavaScript에서 두 개의 얼룩을 비교하는 방법은 무엇입니까?
나는 그것들이 정확히 동일한 지 비교하기 위해 비교하기를 원합니다.
(blob1 === blob2)은 각 blob의보고 된 크기가 574 바이트이지만 false를 반환합니다. 내가 도대체 뭘 잘못하고있는 겁니까?
getHTTPAsBlob(url, callback) {
let cacheBust = Math.random().toString()
url = url + '?&cachebust=' + cacheBust
let xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (xhr.status == 200) {
// get binary data as a response
let fileData = this.response;
let contentType = xhr.getResponseHeader("content-type")
var reader = new FileReader()
reader.onload = (e) => {
console.log(reader.result)
console.log(fileData)
callback(null, {
Body: reader.result,
Blob: fileData,
ContentType: contentType,
Etag: null,
LastModified: null,
})
}
reader.readAsText(fileData)
} else {
callback(xhr)
}
}
xhr.send();
}
FileReader를 사용하여 내용을 비교하려면 "blob"을 읽어야한다고 생각합니다. 특히 "arraybuffer"에 responseType을 설정하는 것이 더 쉽지 않을까요? – Thilo
내 코드를 보면 blob에서 텍스트를 가져 오는 데 filereader를 사용하지만 두 점을 비교할 때 읽기가 필요하지는 않습니다. –
@DukeDugal : 왜 두 개의 얼룩을 비교할 때 읽기가 필요하지 않습니까? 그 내용이 아닌 다른 방법은 무엇입니까? – Thilo