Skip to content

Commit d4f5df6

Browse files
committed
fix: Change function to return File instead of Blob
1 parent d933bc8 commit d4f5df6

8 files changed

+21
-21
lines changed

coverage/index.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ <h1>All files</h1>
3030

3131

3232
<div class='fl pad1y space-right2'>
33-
<span class="strong">70.83% </span>
33+
<span class="strong">70.37% </span>
3434
<span class="quiet">Branches</span>
35-
<span class='fraction'>153/216</span>
35+
<span class='fraction'>152/216</span>
3636
</div>
3737

3838

@@ -85,8 +85,8 @@ <h1>All files</h1>
8585
</td>
8686
<td data-value="88.13" class="pct high">88.13%</td>
8787
<td data-value="430" class="abs high">379/430</td>
88-
<td data-value="70.83" class="pct medium">70.83%</td>
89-
<td data-value="216" class="abs medium">153/216</td>
88+
<td data-value="70.37" class="pct medium">70.37%</td>
89+
<td data-value="216" class="abs medium">152/216</td>
9090
<td data-value="92.85" class="pct high">92.85%</td>
9191
<td data-value="42" class="abs high">39/42</td>
9292
<td data-value="89.61" class="pct high">89.61%</td>
@@ -116,7 +116,7 @@ <h1>All files</h1>
116116
<div class='footer quiet pad2 space-top1 center small'>
117117
Code coverage generated by
118118
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
119-
at 2023-03-06T13:46:27.026Z
119+
at 2023-07-12T16:04:59.831Z
120120
</div>
121121
<script src="prettify.js"></script>
122122
<script>

coverage/lcov-report/index.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ <h1>All files</h1>
3030

3131

3232
<div class='fl pad1y space-right2'>
33-
<span class="strong">70.83% </span>
33+
<span class="strong">70.37% </span>
3434
<span class="quiet">Branches</span>
35-
<span class='fraction'>153/216</span>
35+
<span class='fraction'>152/216</span>
3636
</div>
3737

3838

@@ -85,8 +85,8 @@ <h1>All files</h1>
8585
</td>
8686
<td data-value="88.13" class="pct high">88.13%</td>
8787
<td data-value="430" class="abs high">379/430</td>
88-
<td data-value="70.83" class="pct medium">70.83%</td>
89-
<td data-value="216" class="abs medium">153/216</td>
88+
<td data-value="70.37" class="pct medium">70.37%</td>
89+
<td data-value="216" class="abs medium">152/216</td>
9090
<td data-value="92.85" class="pct high">92.85%</td>
9191
<td data-value="42" class="abs high">39/42</td>
9292
<td data-value="89.61" class="pct high">89.61%</td>
@@ -116,7 +116,7 @@ <h1>All files</h1>
116116
<div class='footer quiet pad2 space-top1 center small'>
117117
Code coverage generated by
118118
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
119-
at 2023-03-06T13:46:27.066Z
119+
at 2023-07-12T16:04:59.862Z
120120
</div>
121121
<script src="prettify.js"></script>
122122
<script>

dist/browser-image-compression.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser-image-compression.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser-image-compression.mjs

+1-1
Large diffs are not rendered by default.

dist/browser-image-compression.mjs.map

+1-1
Large diffs are not rendered by default.

lib/image-compression.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
* @param {boolean} [options.alwaysKeepResolution=false]
2626
* @param {AbortSignal} [options.signal]
2727
* @param {number} previousProgress - for internal try catch rerunning start from previous progress
28-
* @returns {Promise<File | Blob>}
28+
* @returns {Promise<File>}
2929
*/
3030
export default async function compress(file, options, previousProgress = 0) {
3131
let progress = previousProgress;
@@ -137,5 +137,6 @@ export default async function compress(file, options, previousProgress = 0) {
137137
cleanupCanvasMemory(origCanvas);
138138

139139
setProgress(100);
140+
compressedFile = new File([compressedFile], file.name, { type: file.type });
140141
return compressedFile;
141142
}

lib/utils.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const CustomFileReader = (isBrowser || inWebWorker) && ((moduleMapper &&
1717
* @param {string} dataUrl
1818
* @param {string} filename
1919
* @param {number} [lastModified=Date.now()]
20-
* @returns {Promise<File | Blob>}
20+
* @returns {Promise<File>}
2121
*/
2222
export function getFilefromDataUrl(dataUrl, filename, lastModified = Date.now()) {
2323
return new Promise((resolve) => {
@@ -29,9 +29,8 @@ export function getFilefromDataUrl(dataUrl, filename, lastModified = Date.now())
2929
while (n--) {
3030
u8arr[n] = bstr.charCodeAt(n);
3131
}
32-
const file = new Blob([u8arr], { type: mime });
33-
file.name = filename;
34-
file.lastModified = lastModified;
32+
const blobFile = new Blob([u8arr], { type: mime });
33+
const file = new File([blobFile], filename, { lastModified, type: blobFile.type });
3534
resolve(file);
3635

3736
// Safari has issue with File constructor not being able to POST in FormData
@@ -251,7 +250,7 @@ export async function drawFileInCanvas(file, options = {}) {
251250
* @param {string} fileName
252251
* @param {number} fileLastModified
253252
* @param {number} [quality]
254-
* @returns {Promise<File | Blob>}
253+
* @returns {Promise<File>}
255254
*/
256255
export async function canvasToFile(canvas, fileType, fileName, fileLastModified, quality = 1) {
257256
let file;
@@ -280,7 +279,7 @@ export async function canvasToFile(canvas, fileType, fileName, fileLastModified,
280279
const dataUrl = canvas.toDataURL(fileType, quality);
281280
file = await getFilefromDataUrl(dataUrl, fileName, fileLastModified);
282281
}
283-
return file;
282+
return new File([file], fileName, { lastModified: file.lastModified, type: file.type });
284283
}
285284

286285
/**

0 commit comments

Comments
 (0)