UNPKG

feedbaby-client

Version:
63 lines (62 loc) 2.45 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const adm_zip_1 = __importDefault(require("adm-zip")); class AppDataAdmZip { constructor(zip, feedFile, growthFile, medicineFile) { this.zip = zip; this.feedFile = feedFile; this.growthFile = growthFile; this.medicineFile = medicineFile; } getFeeds() { return __awaiter(this, void 0, void 0, function* () { return this.read(this.feedFile); }); } getGrowths() { return __awaiter(this, void 0, void 0, function* () { return this.read(this.growthFile); }); } getMedicines() { return __awaiter(this, void 0, void 0, function* () { return this.read(this.medicineFile); }); } getBuffer() { return this.zip.toBuffer(); } read(csvFile) { const entry = this.zip.getEntry(csvFile.getFilename()); // TODO Does this throw an error if the file doesn't exist? return csvFile.read(entry.getData()); } } exports.AppDataAdmZip = AppDataAdmZip; class AppDataAdmZipReader { constructor(feedFile, growthFile, medicineFile) { this.feedFile = feedFile; this.growthFile = growthFile; this.medicineFile = medicineFile; } read(zip) { const admZip = new adm_zip_1.default(zip); AppDataAdmZipReader.checkValidZip(admZip); return new AppDataAdmZip(admZip, this.feedFile, this.growthFile, this.medicineFile); } static checkValidZip(zip) { zip.getZipComment(); } } exports.AppDataAdmZipReader = AppDataAdmZipReader;