1.1.0 • Published 7 years ago

wxapp-file_reqst v1.1.0

Weekly downloads
1
License
GPL-3.0
Repository
-
Last release
7 years ago

wxapp-file-reqst

A module to manage files and offer a request queue in wxapp.

Import

var file_reqst = require('/path/to/file_reqst.js');

Usage

  1. getRemainSpace()

    This will return the remaining space of local file storage.

    Page({
      ...
      someMethod: function(){
        ...
      	remainingSpace = file_reqst.getRemainSpace();
      	...
      }
    })

  2. downloadAndSave(obj)

    Required object format:

    keytyperequiredvalue
    urlStringtruethe url to download resources.
    nameStringfalserename the file.(default is download name)
    collisionStringfalse'both' or 'older' or 'newer'.(default is 'newer')
    csnameStringfalsewhen collision is set to 'both', file will be renamed to csname.
    headerObjectfalserequest header.
    successFunctionfalsethe callback when successfully saved.
    failFunctionfalsethe callback when save failed.
    completeFunctionfalsethe callback when save completed.

    P.S. csname is required when collision is set to 'both'.

    ...
    file_reqst.downloadAndSave({
      url: 'https://example.com/file/path',
      name: 'rename.ext'
    });
    ...
  3. getAllFiles()

    This will return all the files managed by file_reqst.js.

  4. getFile(name, callback)

    This will return the file path corresponding to the name. And the callback will receive an object like the following one:

    {
      filePath: 'path/to/your/file',
      createTime: 1490870527394,
      size: 233
    }

    P.S. An Exception will be thrown when file doesn't exist.

  5. removeFile(name, callback)

    The callback will receive an object like the following one:

    {
      message: 'fail',
      info: {something provided by wxapp}
    }
    {
      message: 'ok',
      info: {something provided by wxapp}
    }
  6. clearFile(callback)

    The callback will receive an object like removeFile received.

Support

ZLab

z-jack(GitHub)

npm