Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 2f234b9

Browse files
committed
Export FileSystem helper
1 parent fa5a1b9 commit 2f234b9

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/index.tsx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ const imageCacheHoc = <P extends object>(
101101
* @returns {Promise} promise that resolves to an object that contains cached file info.
102102
*/
103103
static async cacheFile(url: string): Promise<any> {
104-
const fileSystem = FileSystemFactory(
105-
options.cachePruneTriggerLimit || null,
106-
options.fileDirName || null,
107-
)
108-
const localFilePath = await fileSystem.getLocalFilePathFromUrl(url)
104+
const localFilePath = await this.fileSystem().getLocalFilePathFromUrl(url)
109105

110106
return {
111107
url: url,
@@ -134,11 +130,7 @@ const imageCacheHoc = <P extends object>(
134130
mtime?: Date,
135131
ctime?: Date,
136132
) {
137-
const fileSystem = FileSystemFactory(
138-
options.cachePruneTriggerLimit || null,
139-
options.fileDirName || null,
140-
)
141-
return fileSystem.cacheLocalFile(local, url, move, mtime, ctime)
133+
return this.fileSystem().cacheLocalFile(local, url, move, mtime, ctime)
142134
}
143135

144136
/**
@@ -149,12 +141,16 @@ const imageCacheHoc = <P extends object>(
149141
* @returns {Promise} promise that resolves to an object that contains the flush results.
150142
*/
151143
static async flush() {
152-
const fileSystem = FileSystemFactory(
153-
options.cachePruneTriggerLimit || null,
154-
options.fileDirName || null,
155-
)
144+
return this.fileSystem().unlink('')
145+
}
156146

157-
return fileSystem.unlink('')
147+
/**
148+
* Export FileSystem for convenience.
149+
*
150+
* @returns {FileSystem}
151+
*/
152+
static fileSystem() {
153+
return FileSystemFactory(options.cachePruneTriggerLimit || null, options.fileDirName || null)
158154
}
159155

160156
constructor(props: P) {

0 commit comments

Comments
 (0)