-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageStorage.d.ts
75 lines (75 loc) · 3.54 KB
/
ImageStorage.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/// <reference types="node" />
import { ImageInfo } from ".";
export interface ImageStorage {
/**
* Returns the last modified time of the file.
* @param filePath File path to original image.
* @return Promise that resolves to last modified time or null if file could not be found.
*/
getLastModified(filePath: string, width: number, format: string): Promise<number | null>;
/**
* Loads an image from storage.
* @param filePath File path to original image.
* @param width Width to scale image to.
* @param format Format to convert image to.
* @return Promise that resolves to image info or null if image with specified parameters could not be found.
*/
getImage(filePath: string, width: number, format: string): Promise<ImageInfo | null>;
/**
* Stores an image in storage.
* @param filePath File path to original image.
* @param width Width to scale image to.
* @param format Format to convert image to.
* @param imageData Image data to store.
* @return Promise that resolves when image has been stored.
*/
putImage(filePath: string, width: number, format: string, imageData: Buffer): Promise<void>;
}
export type ImageCacheStorageProps = {
/** Path relative to project root where scaled images should be stored.
* If null scaled images won't be cached.
* Defaults to './cache'
*/
cacheDir?: string | null;
/**
* Maximum size of the cache directory in MB.
* If max size is reached and a new image is about to be stored, the longest unused image will be deleted.
* Defaults to 1000 (1GB), zero or negative numbers disable the cache size limit.
*/
cacheSize?: number;
};
/** Creates a directory with limited size containing the latest used formats. */
export declare class ImageCacheStorage implements ImageStorage {
private readonly cacheDir;
private readonly cacheSize;
constructor(options: ImageCacheStorageProps);
/**
* Manually enforces cache cleanup.
* In particular, this is useful if cache was manipulated manually.
* By default this is called automatically when a new image is stored in the cache.
*/
private cleanUpCache;
private getCacheFilePath;
getLastModified(filePath: string, width: number, format: string): Promise<number | null>;
getImage(filePath: string, width: number, format: string): Promise<ImageInfo | null>;
putImage(filePath: string, width: number, format: string, imageData: Buffer): Promise<void>;
}
export type ImageDirectoryStorageProps = {
/** Path relative to project root where scaled images should be stored.*/
dirPath: string;
};
export declare class ImageDirectoryStorage implements ImageStorage {
private dirPath;
constructor(options: ImageDirectoryStorageProps);
private getStoreFilePath;
getLastModified(filePath: string, width: number, format: string): Promise<number | null>;
getImage(filePath: string, width: number, format: string): Promise<ImageInfo | null>;
putImage(filePath: string, width: number, format: string, imageData: Buffer): Promise<void>;
}
/** For each image creates a subdirectory in place that will contain all the different formats. */
export declare class ImageInPlaceStorage implements ImageStorage {
private _getStorageFilePath;
getLastModified(filePath: string, width: number, format: string): Promise<number | null>;
getImage(filePath: string, width: number, format: string): Promise<ImageInfo | null>;
putImage(filePath: string, width: number, format: string, imageData: Buffer): Promise<void>;
}