@sendsafely/sendsafely 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/FileUtil.js +13 -3
  2. package/package.json +1 -1
package/lib/FileUtil.js CHANGED
@@ -29,6 +29,7 @@ function FileUtil(param) {
29
29
  this.eof = false;
30
30
  this.data = [];
31
31
  this.tempSize = 0;
32
+ this.part = 1;
32
33
 
33
34
  this.init = function() {
34
35
  return new Promise(function(resolve) {
@@ -40,7 +41,7 @@ function FileUtil(param) {
40
41
  myself.file.name = path.basename(myself.filePath);
41
42
 
42
43
  if(myself.file.size > (myself.SEGMENT_SIZE/4)) {
43
- myself.file.totalParts = Math.ceil((myself.file.size-(myself.SEGMENT_SIZE/4))/myself.SEGMENT_SIZE);
44
+ myself.file.totalParts = 1 + Math.ceil((myself.file.size-(myself.SEGMENT_SIZE/4))/myself.SEGMENT_SIZE);
44
45
  } else {
45
46
  myself.file.totalParts = 1;
46
47
  }
@@ -56,9 +57,14 @@ function FileUtil(param) {
56
57
 
57
58
  myself.readableStream.on('end', function() {
58
59
  // done reading file
59
- if(!myself.eof) {
60
- myself.eof = true;
60
+ myself.eof = true;
61
+ if(myself.part === myself.file.totalParts) {
61
62
  callback(true);
63
+ } else {
64
+ // increment extra part if file size is less than segment/4
65
+ // so that we callback with an empty array
66
+ myself.part++;
67
+ callback(false);
62
68
  }
63
69
  });
64
70
  }
@@ -71,11 +77,15 @@ function FileUtil(param) {
71
77
  if(!myself.reading && !myself.eof) {
72
78
  myself.reading = true;
73
79
  processChunk();
80
+ } else if(myself.part === myself.file.totalParts) {
81
+ //extra part padding with empty array if file size is less than segment/4
82
+ callback(true);
74
83
  }
75
84
  }
76
85
 
77
86
  function processChunk() {
78
87
  if(myself.tempSize === myself.SEGMENT_SIZE) {
88
+ myself.part++;
79
89
  // callback when data size reaches SEGMENT_SIZE
80
90
  callback(false);
81
91
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendsafely/sendsafely",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "main": "./lib/SendSafely.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"