C++ (Qt)// файлы должны быть открыты и позиции записи/чтения установленыbool CopyFrom( QFile & inF, QFile & outF, qint64 total = -1 ){ char buf[64 * 1024]; if (total < 0) total = inF.size() - inF.pos(); while (total > 0) { qint64 num = qMin(total, (qint64) sizeof(buf)); inF.read(buf, num); outF.write(buf, num); if (inF.error() || outF.error()) return false; total -= num; } return true;}
C++ (Qt)// файлы должны быть открыты и позиции записи/чтения установленыbool CopyFrom( QFile & inF, QFile & outF, qint64 total = -1 ){ char buf[64 * 1024]; if (total < 0) total = inF.size() - inF.pos(); while (total > 0) { qint64 num = qMax(total, (qint64) sizeof(buf)); // <<<<< ??? inF.read(buf, num); outF.write(buf, num); if (inF.error() || outF.error()) return false; total -= num; } return true;}
C++ (Qt)QFile outF(put + "1");outF.open(QIODevice::WriteOnly | QIODevice::Truncate); const char * sign = "zashifrovano"; // "encrypted"outF.write(sign, strlen(sign)); QFile inF(put);inF.open(QIODevice::ReadOnly);bool ok = CopyFrom(inF, outF);
C++ (Qt) QByteArray fl_header(320, 0); ...... // открываем файлы QFile inpf(full_fname); QFile outf(out_fname); // для чтения if (!inpf.open(QIODevice::ReadOnly)) { msgBox.setText("Error: can't open input file"); msgBox.exec(); goto met_ret; } // для записи if (!outf.open(QIODevice::WriteOnly)) { msgBox.setText("Error: can't open output file"); msgBox.exec(); goto met_ret; } // записываем заголовок outf.write(fl_header); cx = 0; // цикл записи файла while(!inpf.atEnd()) { QByteArray src = inpf.read(1024); const int sz = src.size(); QByteArray dst(sz, 0); for(int i = 0; i < sz; ++i) {dst[i] = fn_Shifr_byte(src[i]);} outf.write(dst); cx++; if(!(cx % 100)) { ui->lineEdit_byt->setText(QString::number(cx)); QApplication::processEvents(); } } met_ret: inpf.close(); outf.close();