Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
cordova-file-cache
Advanced tools
Super Awesome File Cache for Cordova Apps
# fetch code using bower
bower install cordova-file-cache cordova-promise-fs
# ...or npm...
npm install cordova-file-cache cordova-promise-fs
# or just download and include the javascript
curl https://raw.githubusercontent.com/markmarijnissen/cordova-promise-fs/master/CordovaPromiseFS.js
curl https://raw.githubusercontent.com/markmarijnissen/cordova-file-cache/master/CordovaFileCache.js
# install Cordova plugins
cordova plugin add org.apache.cordova.file
cordova plugin add org.apache.cordova.file-transfer # optional
// Initialize a Cache
var cache = CordovaFileCache({
fs: CordovaPromiseFS(),
mode: 'hash', // or 'mirror'
localRoot: 'data',
serverRoot: 'http://yourserver.com/files/' // optional, required on 'mirror' mode
});
cache.ready.then(function(list){
// Promise when cache is ready.
// Returns a list of paths on the FileSystem that are cached.
})
serverRoot
at localRoot
.
// First, add files
cache.add('http://yourserver.com/folder/photo1.jpg')
cache.add('folder/photo2.jpg') // automatically prepends the `severRoot`
cache.add(['photo3.jpg','photo4.jpg'])
// Now the cache is dirty: It needs to download.
cache.isDirty() === true
// cache.add also returns if the cache is dirty.
var dirty = cache.add(['photo3.jpg'])
// Download files.
cache.download(onprogress).then(function(cache){ ... },function(failedDownloads) { ... })
// It is recommended to avoid heavy UI and animation while downloading.
// The optional 'onprogress' event handler is enhanced with information
// about the total download queue:
onprogress = function(ProgressEvent) {
ProgressEvent.index // current download index
ProgressEvent.total // total files to download
}
// Get the cached internalURL of the file: "cdvfile://localhost/persisent/cache/photo3.jpg"
cache.get('photo3.jpg');
cache.toInternalURL('photo3.jpg');
cache.toInternalURL('http://yourserver.com/photo3.jpg');
// Get the file URL of the file: "file://.../photo3.jpg";
cache.toURL('photo3.jpg');
// When file is not cached, the original input is returned as a fallback.
cache.get('http://yoursever.com/never-cached-this.jpg') === 'http://yoursever.com/never-cached-this.jpg'
// Get Base64 encoded data URL.
cache.toDataURL('photo3.jpg').then(function(base64){},function(err){});
// Abort all downloads
cache.abort()
// Clear cache (removes localRoot directory)
cache.clear().then( ... )
// Or remove a single file
cache.remove('photo3.jpg').then( ... )
// Returns path on Cordova Filesystem, i.e. "/cache/photo3.jpg"
cache.toPath('photo3.jpg');
// Returns server URL to download, i.e. "http://yourserver.com/photo3.jpg";
cache.toServerURL('photo3.jpg');
// Needs a download?
cache.isDirty();
// Returns a list of server URLs that need to be downloaded.
cache.getDownloadQueue();
// Return a list of paths that are cached (i.e. ["/cache/photo3.jpg"])
cache.list().then(function(list){...},function(err){...})
Convert CommonJS to a browser-version:
npm install gluejs -g
npm run-script prepublish
Feel free to contribute to this project in any way. The easiest way to support this project is by giving it a star.
© 2014 - Mark Marijnissen
FAQs
Cordova File Cache
The npm package cordova-file-cache receives a total of 15 weekly downloads. As such, cordova-file-cache popularity was classified as not popular.
We found that cordova-file-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.