Giter VIP home page Giter VIP logo

cordova-promise-fs's People

Contributors

dolezel avatar dortzur avatar ijzerenhein avatar jakgra avatar m0ppers avatar markmarijnissen avatar pheinicke avatar sebastian-greco avatar youjenli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-promise-fs's Issues

How to retrieve a downloaded filename when it finished.

Hi,
I am newer to JS program. When use this library, how can I get the downloaded filename, when I try to download a queue url, like:

for each( queue[] )
promiseFS.download(url, savePath, { retry: retry }, progress ).then(onDone, onFail);

Thanks advance!

Android download to external data dir inconsistency

Hi. I have a Cordova application and I would like to download pdf/video files and open them via fileopener on an android device. Because of permission issues, I have to download them to an external/shared location: cordova.file.externalDataDirectory.

This script used to work before, but on this new device I've got, it has some issues. I can't download files to the cordova.file.externalDataDirectory. If I set relative path it downloads it successfully to the cordova.file.dataDirectory, but I can't open it. If I set absolute path to the "to" parameter it breaks.

cordova: v5.6
android: v4.4.2
device: Hudl 2

*This works: *

from = 'https://mywebsite.co.uk/test.pdf';
to = 'file:///storage/emulated/0/Android/data/en.myapp/files/test.pdf';
fileTransfer = new FileTransfer();
fileTransfer.download(
   from, 
   to, 
    function(entry) {
        console.log("download complete: " + entry.toURL());
    },
    function(error) {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("upload error code" + error.code);
    },
    false
);

//gives:
//download complete: file:///storage/emulated/0/Android/data/en.myapp/files/test.pdf
//works fine tested with fileopener

*This doesn't work: *

from = 'https://mywebsite.co.uk/test.pdf';
to = 'file:///storage/emulated/0/Android/data/en.myapp/files/test.pdf';
fs = CordovaPromiseFS({
          persistent: true, // or false
          storageSize: 0, // storage size in bytes - 0 unlimited
          concurrency: 2, // how many concurrent uploads/downloads?
          Promise: Promise // Your favorite Promise/A+ library! 
        });
fs.download(from, to, function(e){console.log(e)}, function(e){console.log(e)})

//gives and object. Snippet:
...

_settledValue: FileEntry
filesystem: FileSystem
fullPath: "/file:/storage/emulated/0/Android/data/en.myapp/files/test.pdf"
isDirectory: false
isFile: true
name: "test.pdf"
nativeURL: "file:///data/data/en.myapp/files/files/file%3A/storage/emulated/0/Android/data/en.myapp/files/test.pdf"
__proto__: utils.extend.F

...

dir() fails on Windows 10

dir() fails consistently on Windows 10 using the latest cordova-plugin-file, 4.3.3.

The core issue seems to be:

  • dir() passes its path to normalize(), which adds a "/" to the end, so "foo/bar" becomes "foo/bar/"

  • on Windows 10, the getDirectory() method of FileProxy.js splits that path based on the last "/" in the path. See the split into name and wpath here: https://github.com/apache/cordova-plugin-file/blob/master/src/windows/FileProxy.js#L758

  • so "foo/bar/" splits into "foo/bar" and ""

  • FileProxy.js then gets the first part, "foo/bar", successfully

  • FileProxy.js then attempts to get the second part, "", relative to the first, but since "" isn't a valid filename, it throws an exception

We're working around this currently by adding a "." to our directory names when we're running on Windows. This fakes normalize() into thinking our directories are files and it therefore doesn't add the final "/". That works, but is pretty ugly.

Download fails on Android when url's contain '../' in it

Download fails on Android when url's contain '../' in it. I'm not entirely sure but IIRC this doesn't seem to be an issue on iOS.

I want to make a PR with a fix but I wanted to check with you if you agree with me that this should be fixed in the function 'normalize'.

Is it okay with you if I improve the function normalize so that it will return a normalized path?

Like this:
"http://10.10.1.104:9000/site//Mobile/../css/tinymce-content.css"
into
"http://10.10.1.104:9000/site/css/tinymce-content.css"

new Blob() - Illegal constructor

Hi!

In certain Android versions (e.g. 4.3) the blob constructor does not work. Using the constructor, an error is thrown: "TypeError: Illegal constructor".

We use cordova-promise-fs in combination with cordova-app-loader, and sometimes on our Android 4.3 test device, the update failes because the blob constructor is used.

The problematic part of the code is the following:

  /* write contents to a file */
  function write(path,blob,mimeType) {
    return ensure(dirname(path))
      .then(function() { return file(path,{create:true}); })
      .then(function(fileEntry) {
        return new Promise(function(resolve,reject){
          fileEntry.createWriter(function(writer){
            writer.onwriteend = resolve;
            writer.onerror = reject;
            if(typeof blob === 'string') {
              blob = new Blob([blob],{type: mimeType || 'text/plain'});
            } else if(blob instanceof Blob !== true){
              blob = new Blob([JSON.stringify(blob,null,4)],{type: mimeType || 'application/json'});
            }
            writer.write(blob);
          },reject);
        });
      });
    }

Though deprecated, the BlobBuilder should be used if creating the Blob via constructor fails. See https://developer.mozilla.org/en-US/docs/Web/API/BlobBuilder

I'll try to create a pull request in the next days...

improvements to be able to work with the library in the browser

I'm developing a Cordova application and wanted to be able to debug it without a device (using the browser platform). I finally managed to get it working but had to perform several steps:

  1. I had to force the isCordova check to false in order to be able to work with the library. Otherwise I received the following error (Could not get Cordova FileSystem: FileError {code: "Missing Command Error"})

  2. I also needed to explicitly request file quota to be able to work with persistent storage. I did it by executing webkitStorageInfo.requestQuota(webkitStorageInfo.PERSISTENT, options.storageSize); after the fs initialization.

  3. In order to be able to correctly save downloaded binary files I had to set the respose type of the xhr fnction to blob (xhr.responseType='blob';) and write(file,xhr.response).then(win,fail);. In my tests it worked for every file type, but it could be changed to work with text, array, etc, depending on the options passed to the download function.

  4. Finally, I had to launch chrome with the flags --disable-web-security --allow-file-access-from-files --user-data-dir=datadir and manually allow file storage in the browser

I think it would be great to be able to configure the behaviour for the items 1,2,3 in the options of CordovaPromiseFS.

In any case, many thanks as cordova-promise-fs it is a wonderful library :)

Global variables cause multiple instances to interfere

Hi. I've been using cordova-app-loader, with the usual code:

var fs = new CordovaPromiseFS({
    Promise: Promise
});
var loader = new CordovaAppLoader({
    fs: fs,
    serverRoot: 'http://example.com/',
    localRoot: 'app',
    cacheBuster: true,
    checkTimeout: 10000
});

This works fine. However, I added another CordovaPromiseFS instance to access another part of the filesystem and it broke the app loader. Now it tries to download files to file:///app/app.js, which obviously won't work.

I ran eslint on cordova-promise-fs/index.js and it seems that the following variables are undeclared and thus global:

  • CDV_URL_ROOT
  • CDV_INTERNAL_URL_ROOT

I think this is a causing the two instances to interfere. Is there a reason for this or can it just be fixed with a couple of vars?

Thanks.

concurrent writes and file corruption on iOS

Hi,

Not sure if this is related to this particular module (maybe a lower level problem) but I'm experiencing file corruption on iOS.

I'm using fs.write() to replace the whole content of a file as a way to save data.
The function maybe called several times in a short period and no particular "waiting for previous write" mechanism has been implemented.
This is working perfectly well on Android but on iOS I sometime get a corrupted file with the whole content plus part off the content after, like if a write appended part of the data instead of replacing it.
Of course this ends in data corruption as the JSON content cannot be parsed anymore :(
I've tried to fs.remove() the file before fs.write() but fs.remove() sometimes fails (with Error code 1 even if mustExists is false)...

Questions:

  • Is it safe to call several fs.write() on the same file ?
  • If not what can I do the work around this problem ?

Thanks a lot,

Julien

require is not defined

I'm try to use this wrapper library to build a simple logger system to log system status of the app into a file locally.
But I got require is not defined issue. If I just delete 'Promise: require('promiscuous')', I will work, but I've tried to log some thing into a created file. But when I try to read it immediately, it's just empty. By the fs.deviceready method, I just got [object Promise].
Any suggestion? Thanks! - Su

function to append data to existing file

I was going to do a pull request which would allow appending to existing files.

Should I add a bool parameter to write which defaults to false or add a new method?

function write(path,blob,mimeType,append)

or

function append(path,blob,mimeType)

Working with JSPM + ES6

Many thanks for this library. Its just what I needed to get cross platform filesystem with promises working in Cordova/Electron(Chrome).

To get it working with using JSPM and ES6 I had to import like this:

import * as CordovaPromiseFS from 'cordova-promise-fs';

and to create an instance I had to:

let fs = CordovaPromiseFS.default({Promise: window.Promise});

I've yet to look into why that was required over the defaults but its working great now and I thought this might help others who are trying the same. Without defining the Promise option I was getting an exception.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.