files.com 1.0.256 → 1.0.258
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -0
- package/_VERSION +1 -1
- package/lib/isomorphic/File.node.js +39 -9
- package/lib/models/File.js +303 -277
- package/package.json +1 -1
- package/shared/normalization_for_comparison_test_data.json +38 -0
- package/src/isomorphic/File.node.js +14 -0
- package/src/models/File.js +15 -0
- package/test/src/index.js +34 -3
package/README.md
CHANGED
@@ -152,6 +152,9 @@ You can set the following global properties using static methods on the `Files`
|
|
152
152
|
|
153
153
|
// download to a writable stream
|
154
154
|
await downloadableFile.downloadToStream(stream)
|
155
|
+
|
156
|
+
// download in memory and return as a UTF-8 string
|
157
|
+
const textContent = await downloadableFile.downloadToString()
|
155
158
|
}
|
156
159
|
|
157
160
|
### Additional Object Documentation
|
package/_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.258
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
4
|
exports.__esModule = true;
|
5
|
-
exports.saveUrlToStream = exports.saveUrlToFile = exports.openDiskFileWriteStream = exports.openDiskFileReadStream = void 0;
|
5
|
+
exports.saveUrlToString = exports.saveUrlToStream = exports.saveUrlToFile = exports.openDiskFileWriteStream = exports.openDiskFileReadStream = void 0;
|
6
6
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
7
7
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
8
8
|
var openDiskFileReadStream = function openDiskFileReadStream(sourceFilePath) {
|
@@ -40,25 +40,55 @@ var saveUrlToStream = /*#__PURE__*/function () {
|
|
40
40
|
};
|
41
41
|
}();
|
42
42
|
exports.saveUrlToStream = saveUrlToStream;
|
43
|
-
var
|
44
|
-
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(url
|
45
|
-
var stream;
|
43
|
+
var saveUrlToString = /*#__PURE__*/function () {
|
44
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(url) {
|
46
45
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
47
46
|
while (1) switch (_context2.prev = _context2.next) {
|
47
|
+
case 0:
|
48
|
+
return _context2.abrupt("return", new Promise(function (resolve, reject) {
|
49
|
+
var https = require('https');
|
50
|
+
https.get(url, function (response) {
|
51
|
+
var chunks = [];
|
52
|
+
response.on('data', function (chunk) {
|
53
|
+
return chunks.push(Buffer.from(chunk));
|
54
|
+
});
|
55
|
+
response.on('end', function () {
|
56
|
+
return resolve(Buffer.concat(chunks).toString('utf8'));
|
57
|
+
});
|
58
|
+
}).on('error', function (error) {
|
59
|
+
reject(error);
|
60
|
+
});
|
61
|
+
}));
|
62
|
+
case 1:
|
63
|
+
case "end":
|
64
|
+
return _context2.stop();
|
65
|
+
}
|
66
|
+
}, _callee2);
|
67
|
+
}));
|
68
|
+
return function saveUrlToString(_x3) {
|
69
|
+
return _ref2.apply(this, arguments);
|
70
|
+
};
|
71
|
+
}();
|
72
|
+
exports.saveUrlToString = saveUrlToString;
|
73
|
+
var saveUrlToFile = /*#__PURE__*/function () {
|
74
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(url, destinationPath) {
|
75
|
+
var stream;
|
76
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
77
|
+
while (1) switch (_context3.prev = _context3.next) {
|
48
78
|
case 0:
|
49
79
|
stream = openDiskFileWriteStream(destinationPath);
|
50
|
-
|
80
|
+
_context3.next = 3;
|
51
81
|
return saveUrlToStream(url, stream);
|
52
82
|
case 3:
|
53
83
|
stream.close();
|
54
84
|
case 4:
|
55
85
|
case "end":
|
56
|
-
return
|
86
|
+
return _context3.stop();
|
57
87
|
}
|
58
|
-
},
|
88
|
+
}, _callee3);
|
59
89
|
}));
|
60
|
-
return function saveUrlToFile(
|
61
|
-
return
|
90
|
+
return function saveUrlToFile(_x4, _x5) {
|
91
|
+
return _ref3.apply(this, arguments);
|
62
92
|
};
|
63
93
|
}();
|
64
94
|
exports.saveUrlToFile = saveUrlToFile;
|