Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uploadFile.js 1.2KB

123456789101112131415161718192021222324252627
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const fs_1 = __importDefault(require("fs"));
  7. const path_1 = __importDefault(require("path"));
  8. const archiver_1 = __importDefault(require("archiver"));
  9. async function uploadFile(localPath) {
  10. if (typeof localPath !== 'string') {
  11. throw new Error('number or type of arguments don\'t agree with uploadFile command');
  12. }
  13. if (typeof this.file !== 'function') {
  14. throw new Error(`The uploadFile command is not available in ${this.capabilities.browserName}`);
  15. }
  16. let zipData = [];
  17. let source = fs_1.default.createReadStream(localPath);
  18. return new Promise((resolve, reject) => {
  19. archiver_1.default('zip')
  20. .on('error', (err) => reject(err))
  21. .on('data', (data) => zipData.push(data))
  22. .on('end', () => this.file(Buffer.concat(zipData).toString('base64')).then((localPath) => resolve(localPath), reject))
  23. .append(source, { name: path_1.default.basename(localPath) })
  24. .finalize();
  25. });
  26. }
  27. exports.default = uploadFile;