summaryrefslogtreecommitdiff
path: root/ftparchive/multicompress.h
blob: a65077e7390b116f76b3c49a518edf56148b3da0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
// $Id: multicompress.h,v 1.2 2001/02/20 07:03:18 jgg Exp $
/* ######################################################################

   MultiCompressor
   
   Multiple output class. Takes a single FILE* and writes it simultaneously
   to many compressed files. Then checks if the resulting output is 
   different from any previous output and overwrites the old files. Care is
   taken to ensure that the new files are not generally readable while they
   are being written.
   
   ##################################################################### */
									/*}}}*/
#ifndef MULTICOMPRESS_H
#define MULTICOMPRESS_H



#include <string>
#include <apt-pkg/fileutl.h>
#include <stdio.h>
#include <sys/types.h>
    
class MultiCompress
{
   // Enumeration of all supported compressors
   struct CompType
   {
      const char *Name;
      const char *Extension;
      const char *Binary;
      const char *CompArgs;
      const char *UnCompArgs;
      unsigned char Cost;
   };

   // An output file
   struct Files
   {
      string Output;
      const CompType *CompressProg;
      Files *Next;      
      FileFd TmpFile;
      pid_t CompressProc;
      time_t OldMTime;
      int Fd;
   };
   
   Files *Outputs;
   pid_t Outputter;
   mode_t Permissions;
   static const CompType Compressors[];

   bool OpenCompress(const CompType *Prog,pid_t &Pid,int FileFd,
		     int &OutFd,bool Comp);
   bool Child(int Fd);
   bool Start();
   bool Die();
   
   public:
   
   // The FD to write to for compression.
   FILE *Input;
   unsigned long UpdateMTime;
   
   bool Finalize(unsigned long &OutSize);
   bool OpenOld(int &Fd,pid_t &Proc);
   bool CloseOld(int Fd,pid_t Proc);
   static bool GetStat(string Output,string Compress,struct stat &St);
   
   MultiCompress(string Output,string Compress,mode_t Permissions,
		 bool Write = true);
   ~MultiCompress();
};

#endif