chrv-components 1.10.2 → 1.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
|
@@ -1646,10 +1646,14 @@ class FileService {
|
|
|
1646
1646
|
this.toBase64WithProgress = (file) => {
|
|
1647
1647
|
return new Observable((observer) => {
|
|
1648
1648
|
const reader = new FileReader();
|
|
1649
|
-
|
|
1649
|
+
// Taille d'un chunk (90 Ko)
|
|
1650
|
+
// DOIT ETRE UN MULTIPLE DE 3
|
|
1651
|
+
// pour des raisons d'encodage Base64
|
|
1652
|
+
const chunkSize = 1024 * 90;
|
|
1650
1653
|
const totalSize = file?.file?.size ?? 0;
|
|
1651
|
-
|
|
1652
|
-
let
|
|
1654
|
+
// Position
|
|
1655
|
+
let offset = 0;
|
|
1656
|
+
let base64Data = '';
|
|
1653
1657
|
const indexOfExtension = file?.file?.name.lastIndexOf('.');
|
|
1654
1658
|
if (!indexOfExtension || indexOfExtension === -1) {
|
|
1655
1659
|
observer.error('[FileService] Invalid file name: no file extension found.');
|
|
@@ -1657,7 +1661,7 @@ class FileService {
|
|
|
1657
1661
|
}
|
|
1658
1662
|
const [name, extension] = [
|
|
1659
1663
|
file.file.name.slice(0, indexOfExtension),
|
|
1660
|
-
file.file.name.slice(indexOfExtension + 1),
|
|
1664
|
+
file.file.name.slice(indexOfExtension + 1),
|
|
1661
1665
|
];
|
|
1662
1666
|
file = {
|
|
1663
1667
|
...file,
|
|
@@ -1667,27 +1671,24 @@ class FileService {
|
|
|
1667
1671
|
};
|
|
1668
1672
|
const readChunk = () => {
|
|
1669
1673
|
const chunk = file.file.slice(offset, offset + chunkSize);
|
|
1670
|
-
reader.readAsDataURL(chunk);
|
|
1674
|
+
reader.readAsDataURL(chunk);
|
|
1671
1675
|
};
|
|
1672
1676
|
reader.onload = (event) => {
|
|
1673
|
-
// Concaténer les données du chunk actuel
|
|
1674
1677
|
const result = event.target.result;
|
|
1675
|
-
|
|
1678
|
+
// Retire l'entête qui est rajoutée à chaque lecture
|
|
1679
|
+
const base64Chunk = result.split(',')[1];
|
|
1676
1680
|
base64Data += base64Chunk;
|
|
1677
|
-
// Mettre à jour l'offset et calculer la progression
|
|
1678
1681
|
offset += chunkSize;
|
|
1679
1682
|
const progress = Math.min(Math.round((offset / totalSize) * 100), 100);
|
|
1680
|
-
// Émettre l'événement de progression
|
|
1681
1683
|
observer.next({ progress, file });
|
|
1682
1684
|
if (offset < totalSize) {
|
|
1683
|
-
// Lire le prochain chunk
|
|
1684
1685
|
readChunk();
|
|
1685
1686
|
}
|
|
1686
1687
|
else {
|
|
1687
|
-
//
|
|
1688
|
+
// On termine l'encodage en rajoutant les métadata et en mettant à jour la dataurl
|
|
1688
1689
|
file.data = `data:${file.file.type};base64,${base64Data}`;
|
|
1689
1690
|
file.url = window.URL.createObjectURL(file.file);
|
|
1690
|
-
observer.next({ progress: 100, file });
|
|
1691
|
+
observer.next({ progress: 100, file });
|
|
1691
1692
|
observer.complete();
|
|
1692
1693
|
}
|
|
1693
1694
|
};
|