Skip to content

Commit aade93e

Browse files
v1.0.257
[Bot] push changes from Files.com
1 parent 0b5c02a commit aade93e

File tree

7 files changed

+409
-290
lines changed

7 files changed

+409
-290
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ You can set the following global properties using static methods on the `Files`
152152

153153
// download to a writable stream
154154
await downloadableFile.downloadToStream(stream)
155+
156+
// download in memory and return as a UTF-8 string
157+
const textContent = await downloadableFile.downloadToString()
155158
}
156159

157160
### Additional Object Documentation

_VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.256
1+
1.0.257

lib/isomorphic/File.node.js

+39-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
44
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;
66
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
77
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
88
var openDiskFileReadStream = function openDiskFileReadStream(sourceFilePath) {
@@ -40,25 +40,55 @@ var saveUrlToStream = /*#__PURE__*/function () {
4040
};
4141
}();
4242
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) {
4645
return _regenerator.default.wrap(function _callee2$(_context2) {
4746
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) {
4878
case 0:
4979
stream = openDiskFileWriteStream(destinationPath);
50-
_context2.next = 3;
80+
_context3.next = 3;
5181
return saveUrlToStream(url, stream);
5282
case 3:
5383
stream.close();
5484
case 4:
5585
case "end":
56-
return _context2.stop();
86+
return _context3.stop();
5787
}
58-
}, _callee2);
88+
}, _callee3);
5989
}));
60-
return function saveUrlToFile(_x3, _x4) {
61-
return _ref2.apply(this, arguments);
90+
return function saveUrlToFile(_x4, _x5) {
91+
return _ref3.apply(this, arguments);
6292
};
6393
}();
6494
exports.saveUrlToFile = saveUrlToFile;

0 commit comments

Comments
 (0)