files.com 1.0.256 → 1.0.258

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.
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.256
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 saveUrlToFile = /*#__PURE__*/function () {
44
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(url, destinationPath) {
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
- _context2.next = 3;
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 _context2.stop();
86
+ return _context3.stop();
57
87
  }
58
- }, _callee2);
88
+ }, _callee3);
59
89
  }));
60
- return function saveUrlToFile(_x3, _x4) {
61
- return _ref2.apply(this, arguments);
90
+ return function saveUrlToFile(_x4, _x5) {
91
+ return _ref3.apply(this, arguments);
62
92
  };
63
93
  }();
64
94
  exports.saveUrlToFile = saveUrlToFile;