mdict-parser.js
function sliceThen(file, offset, len) {
    var p = new Promise(function(_resolve) {
      fs.open(file, 'r', function(err, fd){
        if (err) {
          throw err;
        }

        var res = new Buffer(len);
        fs.read(fd, res, 0, len, offset, function(err, bytesRead, buffer){
          if (err) {
            throw err;
          }

          _resolve(buffer);
        });
      });
    });

    /**
     * Call proc with specified arguments prepending with sliced file/blob data (ArrayBuffer) been read.
     * @param the first argument is a function to be executed
     * @param other optional arguments are passed to the function following auto supplied input ArrayBuffer
     * @return a promise object which can be chained with further process through spread() method
     */
    p.exec = function(proc /*, args... */) {
      var args = Array.prototype.slice.call(arguments, 1);
      return p.then(function(data) {
          args.unshift(data);
          var ret = proc.apply(null, args);
          return resolve(ret !== UNDEFINED && ret._spreadus_ ? ret : [ret]);
      });
    };
        
    return p;
  }
function sliceThen(file, offset, len) {
    var p = new Promise(function(_resolve) {
      fs.open(file, 'r', function(err, fd){
        if (err) {
          throw err;
        }

        var res = new Buffer(len);
        fs.read(fd, res, 0, len, offset, function(err, bytesRead, buffer){
          if (err) {
            throw err;
          }

          _resolve(buffer);
        });
      });
    });

    /**
     * Call proc with specified arguments prepending with sliced file/blob data (ArrayBuffer) been read.
     * @param the first argument is a function to be executed
     * @param other optional arguments are passed to the function following auto supplied input ArrayBuffer
     * @return a promise object which can be chained with further process through spread() method
     */
    p.exec = function(proc /*, args... */) {
      var args = Array.prototype.slice.call(arguments, 1);
      return p.then(function(data) {
          args.unshift(data);
          var ret = proc.apply(null, args);
          return resolve(ret !== UNDEFINED && ret._spreadus_ ? ret : [ret]);
      });
    };
        
    return p;
  }
var fd = null; var fdFileName = null;