UNPKG

vpn.email.client

Version:
52 lines (51 loc) 1.74 kB
"use strict"; const Stream = require("stream"); const Compress = require("./compress"); class mainWrite extends Stream.Writable { constructor(imapCluster, password, isSsl, uuid, count) { super(); this.imapCluster = imapCluster; this.password = password; this.isSsl = isSsl; this.uuid = uuid; this.count = count; this.src = null; } packageBuffer(buffer, enpty) { if (!enpty) { return Compress.packetBuffer(5, this.count++, this.uuid, buffer); } Compress.encrypt(buffer, this.password, (err, data) => { return Compress.packetBuffer(0, this.count++, this.uuid, data); }); } _write(chunk, encoding, down) { console.log(`[${this.uuid}] got data ${chunk.length}`); if (chunk.length < 3000 || this.isSsl && this.count < 6) { this.imapCluster.pushMainData(this.packageBuffer(chunk, false)); return down(); } const data = this.imapCluster.getDataUuid(this.uuid) || { buffer: null, uuid: this.uuid, index: this.count++, noExcrypt: this.isSsl }; if (data.buffer) { console.log('imapCluster.getDataUuid find data'); data.buffer = Buffer.concat([data.buffer, chunk]); } else { data.buffer = chunk; } this.imapCluster.pushData(data); return down(); } sendEnd() { const buffer = Compress.packetBuffer(2, this.count, this.uuid, null); this.imapCluster.pushMainData(buffer); } } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = mainWrite;