Manav Rathi 1 年之前
父節點
當前提交
acedbdbe7d
共有 1 個文件被更改,包括 29 次插入0 次删除
  1. 29 0
      web/packages/next/cache.ts

+ 29 - 0
web/packages/next/cache.ts

@@ -82,6 +82,35 @@ export interface EnteCache {
 export const openCache = async (name: CacheName): Promise<EnteCache> =>
 export const openCache = async (name: CacheName): Promise<EnteCache> =>
     isElectron() ? openOPFSCacheWeb(name) : openWebCache(name);
     isElectron() ? openOPFSCacheWeb(name) : openWebCache(name);
 
 
+/**
+ * [Note: ArrayBuffer vs Blob vs Uint8Array]
+ *
+ * ArrayBuffers are in memory, while blobs are unreified, and can directly point
+ * to on disk objects too.
+ *
+ * If we are just passing data around without necessarily needing to manipulate
+ * it, and we already have a blob, it's best to just pass that blob. Further,
+ * blobs also retains the file's encoding information , and are thus a layer
+ * above array buffers which are just raw byte sequences.
+ *
+ * ArrayBuffers are not directly manipulatable, which is where some sort of a
+ * typed array or a data view comes into the picture. The typed `Uint8Array` is
+ * a common way.
+ *
+ * To convert from ArrayBuffer to Uint8Array,
+ *
+ *     new Uint8Array(arrayBuffer)
+ *
+ * Blobs are immutable, but a usual scenario is storing an entire file in a
+ * blob, and when the need comes to display it, we can obtain a URL for it using
+ *
+ *     URL.createObjectURL(blob)
+ *
+ * Refs:
+ * - https://github.com/yigitunallar/arraybuffer-vs-blob
+ * - https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob
+ */
+
 /** An implementation of {@link EnteCache} using Web Cache APIs */
 /** An implementation of {@link EnteCache} using Web Cache APIs */
 const openWebCache = async (name: CacheName) => {
 const openWebCache = async (name: CacheName) => {
     const cache = await caches.open(name);
     const cache = await caches.open(name);