example_tc_gzip.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #include "util/tc_file.h"
  17. #include "util/tc_gzip.h"
  18. #include "util/tc_common.h"
  19. using namespace tars;
  20. int main(int argc, char *argv[])
  21. {
  22. try
  23. {
  24. vector<char> file;
  25. TC_File::load2str("./example_tc_gzip.cpp", file);
  26. {
  27. vector<char> v;
  28. tars::TC_GZip::compress(&file[0], file.size(), v);
  29. cout << "compress ok, size:" << v.size() << endl;
  30. vector<char> s1;
  31. tars::TC_GZip::uncompress(&v[0], v.size(), s1);
  32. assert(file == s1);
  33. }
  34. }
  35. catch(exception &ex)
  36. {
  37. cout << ex.what() << endl;
  38. }
  39. return 0;
  40. }