@@ -782,7 +782,50 @@ function files(p5, fn){
782
782
}
783
783
}
784
784
} ;
785
-
785
+
786
+ /**
787
+ * Loads a file at the given path as a Blob, then returns the resulting data or
788
+ * passes it to a success callback function, if provided. On load, this function
789
+ * returns a `Promise` that resolves to a Blob containing the file data.
790
+ *
791
+ * @method loadBlob
792
+ * @param {String|Request } path - The path or Request object pointing to the file
793
+ * you want to load.
794
+ * @param {Function } [successCallback] - Optional. A function to be called if the
795
+ * file successfully loads, receiving the
796
+ * resulting Blob as its only argument.
797
+ * @param {Function } [errorCallback] - Optional. A function to be called if an
798
+ * error occurs during loading; receives the
799
+ * error object as its only argument.
800
+ * @returns {Promise<Blob> } A promise that resolves with the loaded Blob.
801
+ *
802
+ * @example
803
+ * <div>
804
+ * <code>
805
+ * let myBlob;
806
+ *
807
+ * async function setup() {
808
+ * createCanvas(200, 200);
809
+ * background(220);
810
+ * try {
811
+ * // 1. Load an image file as a Blob.
812
+ * myBlob = await loadBlob('assets/flower-1.png');
813
+ *
814
+ * // 2. Convert the Blob into an object URL.
815
+ * const objectUrl = URL.createObjectURL(myBlob);
816
+ *
817
+ * // 3. Load that object URL into a p5.Image.
818
+ * loadImage(objectUrl, (img) => {
819
+ * // 4. Display the loaded image.
820
+ * image(img, 0, 0, width, height);
821
+ * });
822
+ * } catch (err) {
823
+ * console.error('Error loading blob:', err);
824
+ * }
825
+ * }
826
+ * </code>
827
+ * </div>
828
+ */
786
829
fn . loadBlob = async function ( path , successCallback , errorCallback ) {
787
830
try {
788
831
const { data } = await request ( path , 'blob' ) ;
0 commit comments