Skip to content

Commit 2bc7edf

Browse files
committed
The name of the decompressed file is now the name of the compressed file minua the knz extension
1 parent c65f292 commit 2bc7edf

File tree

2 files changed

+22
-81
lines changed

2 files changed

+22
-81
lines changed

src/app/BlockCompressor.cpp

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ int BlockCompressor::compress(uint64& outputSize)
172172
int nbFiles = 1;
173173
Printer log(cout);
174174
stringstream ss;
175-
string str = _inputName;
176-
transform(str.begin(), str.end(), str.begin(), ::toupper);
177-
bool isStdIn = str == "STDIN";
175+
string upperInputName = _inputName;
176+
transform(upperInputName.begin(), upperInputName.end(), upperInputName.begin(), ::toupper);
177+
bool isStdIn = upperInputName == "STDIN";
178178

179179
if (isStdIn == false) {
180180
vector<string> errors;
@@ -314,45 +314,7 @@ int BlockCompressor::compress(uint64& outputSize)
314314
_ctx.putInt("verbosity", _verbosity);
315315

316316
// Run the task(s)
317-
if (nbFiles == 1) {
318-
string oName = formattedOutName;
319-
string iName = "STDIN";
320-
321-
if (isStdIn == true) {
322-
if (oName.length() == 0) {
323-
oName = "STDOUT";
324-
}
325-
} else {
326-
iName = files[0].fullPath();
327-
_ctx.putLong("fileSize", files[0]._size);
328-
329-
// Set the block size to optimize compression ratio when possible
330-
if ((_autoBlockSize == true) && (_jobs > 0)) {
331-
const int64 bl = files[0]._size / _jobs;
332-
_blockSize = int(max(min((bl + 63) & ~63, int64(MAX_BLOCK_SIZE)), int64(MIN_BLOCK_SIZE)));
333-
}
334-
335-
if (oName.length() == 0) {
336-
oName = iName + ".knz";
337-
}
338-
else if ((inputIsDir == true) && (specialOutput == false)) {
339-
oName = formattedOutName + iName.substr(formattedInName.size()) + ".knz";
340-
}
341-
}
342-
343-
_ctx.putString("inputName", iName);
344-
_ctx.putString("outputName", oName);
345-
FileCompressTask<FileCompressResult> task(_ctx, _listeners);
346-
FileCompressResult fcr = task.run();
347-
res = fcr._code;
348-
read = fcr._read;
349-
written = fcr._written;
350-
351-
if (res != 0) {
352-
cerr << fcr._errMsg << endl;
353-
}
354-
}
355-
else {
317+
{
356318
vector<FileCompressTask<FileCompressResult>*> tasks;
357319
vector<int> jobsPerTask(nbFiles);
358320
Global::computeJobsPerTask(jobsPerTask.data(), _jobs, nbFiles);

src/app/BlockDecompressor.cpp

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ int BlockDecompressor::decompress(uint64& inputSize)
8383
int nbFiles = 1;
8484
Printer log(cout);
8585
stringstream ss;
86-
string str = _inputName;
87-
transform(str.begin(), str.end(), str.begin(), ::toupper);
88-
bool isStdIn = str == "STDIN";
86+
string upperInputName = _inputName;
87+
transform(upperInputName.begin(), upperInputName.end(), upperInputName.begin(), ::toupper);
88+
bool isStdIn = upperInputName == "STDIN";
8989

9090
if (isStdIn == false) {
9191
vector<string> errors;
@@ -204,40 +204,7 @@ int BlockDecompressor::decompress(uint64& inputSize)
204204
_ctx.putInt("verbosity", _verbosity);
205205

206206
// Run the task(s)
207-
if (nbFiles == 1) {
208-
string oName = formattedOutName;
209-
string iName = "STDIN";
210-
211-
212-
if (isStdIn == true) {
213-
if (oName.length() == 0) {
214-
oName = "STDOUT";
215-
}
216-
}
217-
else {
218-
iName = files[0].fullPath();
219-
_ctx.putLong("fileSize", files[0]._size);
220-
221-
if (oName.length() == 0) {
222-
oName = iName + ".bak";
223-
}
224-
else if ((inputIsDir == true) && (specialOutput == false)) {
225-
oName = formattedOutName + iName.substr(formattedInName.size()) + ".bak";
226-
}
227-
}
228-
229-
_ctx.putString("inputName", iName);
230-
_ctx.putString("outputName", oName);
231-
FileDecompressTask<FileDecompressResult> task(_ctx, _listeners);
232-
FileDecompressResult fdr = task.run();
233-
res = fdr._code;
234-
read = fdr._read;
235-
236-
if (res != 0) {
237-
cerr << fdr._errMsg << endl;
238-
}
239-
}
240-
else {
207+
{
241208
vector<FileDecompressTask<FileDecompressResult>*> tasks;
242209
vector<int> jobsPerTask(nbFiles);
243210
Global::computeJobsPerTask(jobsPerTask.data(), _jobs, nbFiles);
@@ -247,12 +214,24 @@ int BlockDecompressor::decompress(uint64& inputSize)
247214
for (int i = 0; i < nbFiles; i++) {
248215
string oName = formattedOutName;
249216
string iName = files[i].fullPath();
217+
upperInputName = iName;
218+
transform(upperInputName.begin(), upperInputName.end(), upperInputName.begin(), ::toupper);
250219

251220
if (oName.length() == 0) {
252-
oName = iName + ".bak";
221+
oName = iName;
222+
223+
if ((upperInputName.length() >= 4) && (upperInputName.substr(upperInputName.length() - 4) == ".KNZ"))
224+
oName.resize(oName.length() - 4);
225+
else
226+
oName = oName + ".bak";
253227
}
254228
else if ((inputIsDir == true) && (specialOutput == false)) {
255-
oName = formattedOutName + iName.substr(formattedInName.size()) + ".bak";
229+
oName = formattedOutName + iName.substr(formattedInName.size());
230+
231+
if ((upperInputName.length() >= 4) && (upperInputName.substr(upperInputName.length() - 4) == ".KNZ"))
232+
oName.resize(oName.length() - 4);
233+
else
234+
oName = oName + ".bak";
256235
}
257236

258237
Context taskCtx(_ctx);

0 commit comments

Comments
 (0)