multicompress.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: multicompress.h,v 1.2 2001/02/20 07:03:18 jgg Exp $
  4. /* ######################################################################
  5. MultiCompressor
  6. Multiple output class. Takes a single FILE* and writes it simultaneously
  7. to many compressed files. Then checks if the resulting output is
  8. different from any previous output and overwrites the old files. Care is
  9. taken to ensure that the new files are not generally readable while they
  10. are being written.
  11. ##################################################################### */
  12. /*}}}*/
  13. #ifndef MULTICOMPRESS_H
  14. #define MULTICOMPRESS_H
  15. #ifdef __GNUG__
  16. #pragma interface "multicompress.h"
  17. #endif
  18. #include <string>
  19. #include <apt-pkg/fileutl.h>
  20. #include <stdio.h>
  21. #include <sys/types.h>
  22. class MultiCompress
  23. {
  24. // Enumeration of all supported compressors
  25. struct CompType
  26. {
  27. const char *Name;
  28. const char *Extension;
  29. const char *Binary;
  30. const char *CompArgs;
  31. const char *UnCompArgs;
  32. unsigned char Cost;
  33. };
  34. // An output file
  35. struct Files
  36. {
  37. string Output;
  38. const CompType *CompressProg;
  39. Files *Next;
  40. FileFd TmpFile;
  41. pid_t CompressProc;
  42. time_t OldMTime;
  43. int Fd;
  44. };
  45. Files *Outputs;
  46. pid_t Outputter;
  47. mode_t Permissions;
  48. static const CompType Compressors[];
  49. bool OpenCompress(const CompType *Prog,pid_t &Pid,int FileFd,
  50. int &OutFd,bool Comp);
  51. bool Child(int Fd);
  52. bool Start();
  53. bool Die();
  54. public:
  55. // The FD to write to for compression.
  56. FILE *Input;
  57. unsigned long UpdateMTime;
  58. bool Finalize(unsigned long &OutSize);
  59. bool OpenOld(int &Fd,pid_t &Proc);
  60. bool CloseOld(int Fd,pid_t Proc);
  61. static bool GetStat(string Output,string Compress,struct stat &St);
  62. MultiCompress(string Output,string Compress,mode_t Permissions,
  63. bool Write = true);
  64. ~MultiCompress();
  65. };
  66. #endif