os_fs.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
25 #include "icl_core/os_fs.h"
26 
27 #include <iostream>
28 
29 #include "icl_core/BaseTypes.h"
30 
31 #ifdef _IC_BUILDER_ZLIB_
32 # include <zlib.h>
33 #endif
34 
35 namespace icl_core {
36 namespace os {
37 
38 #ifdef _IC_BUILDER_ZLIB_
39 bool zipFile(const char *filename, const char *additional_extension)
40 {
41  bool ret = true;
42  icl_core::String gzip_file_name = icl_core::String(filename) + additional_extension + ".gz";
43  char big_buffer[0x1000];
44  int bytes_read = 0;
45  gzFile unzipped_file = gzopen(filename, "rb");
46  gzFile zipped_file = gzopen(gzip_file_name.c_str(), "wb");
47 
48  if (unzipped_file != NULL && zipped_file != NULL)
49  {
50  bytes_read = gzread(unzipped_file, big_buffer, 0x1000);
51  while (bytes_read > 0)
52  {
53  if (gzwrite(zipped_file, big_buffer, bytes_read) != bytes_read)
54  {
55  std::cerr << "ZipFile(" << filename << "->" << gzip_file_name << ") Error on writing." << std::endl;
56  ret = false;
57  break;
58  }
59 
60  bytes_read = gzread(unzipped_file, big_buffer, 0x1000);
61  }
62  }
63 
64  if (unzipped_file != NULL)
65  {
66  gzclose(unzipped_file);
67  }
68  if (zipped_file != NULL)
69  {
70  gzclose(zipped_file);
71  }
72 
73  return ret;
74 }
75 
77 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
78 
79 bool ZipFile(const char *filename, const char *additional_extension)
80 {
81  return zipFile(filename, additional_extension);
82 }
83 
84 #endif
85 
87 #endif
88 
89 }
90 }
ThreadStream & endl(ThreadStream &stream)
Definition: ThreadStream.h:249
Contains global filesystem related functions, encapsulated into the icl_core::os namespace.
std::string String
Definition: BaseTypes.h:43
Contains Interface base classes and base types.


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58