UNPKG

@omnimedia/omnitool

Version:

open source video processing tools

31 lines (24 loc) 770 B
import {GMap} from "@e280/stz" import {Hash} from "./basics.js" import {Media} from "./media.js" import {Resource} from "./resource.js" import {Datafile} from "../utils/datafile.js" export class ResourcePool { #map = new GMap<Hash, Resource.Any> /** store a media file (avoids duplicates via hash) */ async store(datafile: Datafile) { const media = await Media.analyze(datafile) const {hash} = media.datafile.checksum const {filename, url, blob} = media.datafile if (this.#map.has(hash)) { const alreadyExists = this.#map.require(hash) alreadyExists.filename = filename } else this.#map.set(hash, {kind: "media", filename, url, blob, duration: media.duration}) return media } require(hash: Hash) { return this.#map.require(hash) } }