FireSync API
 All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kTar.h
Go to the documentation of this file.
1 
8 #ifndef K_FIRESYNC_TAR_H
9 #define K_FIRESYNC_TAR_H
10 
11 #include <kFireSync/kFsDef.h>
12 
13 #include <kApi/Io/kFile.h>
14 #include <kApi/Io/kPath.h>
15 
22 typedef k32s kTarMode;
23 
25 #define kTAR_MODE_READ (0x01)
26 #define kTAR_MODE_WRITE (0x02)
27 
29 #include <kFireSync/Utils/kTar.x.h>
30 
112 //typedef kObject kTar; --forward-declared in kFsDef.x.h
113 
114 
126 kInlineFx(kStatus) kTar_Archive(const kChar* sourcePath, kStream destStream)
127 {
128  return xkTar_Archive(sourcePath, destStream);
129 }
130 
142 kInlineFx(kStatus) kTar_Archive(const kChar* sourcePath, const kChar* destFilePath)
143 {
144  kFile stream = kNULL;
145 
146  kTry
147  {
148  kTest(kFile_Construct(&stream, destFilePath, kFILE_MODE_WRITE, kNULL));
149 
150  kTest(kTar_Archive(sourcePath, stream));
151  }
152  kFinally
153  {
154  kCheck(kObject_Destroy(stream));
155 
156  kEndFinally();
157  }
158 
159  return kOK;
160 }
161 
170 kInlineFx(kStatus) kTar_Extract(kStream source, const kChar* destParent)
171 {
172  return xkTar_Extract(source, destParent);
173 }
174 
183 kInlineFx(kStatus) kTar_Extract(const kChar* sourcePath, const kChar* destParent)
184 {
185  kFile stream = kNULL;
186 
187  kTry
188  {
189  kTest(kFile_Construct(&stream, sourcePath, kFILE_MODE_READ, kNULL));
190 
191  kTest(kTar_Extract(stream, destParent));
192  }
193  kFinally
194  {
195  kCheck(kObject_Destroy(stream));
196 
197  kEndFinally();
198  }
199 
200  return kOK;
201 }
202 
219 kFsFx(kStatus) kTar_Construct(kTar* tar, kStream stream, kTarMode mode, kAlloc allocator);
220 
233 kFsFx(kStatus) kTar_BeginWrite(kTar tar, const kChar* itemPath, kBool isDirectory, k64u itemSize);
234 
248 kInlineFx(kStatus) kTar_WriteFile(kTar tar, const kChar* itemPath, kStream stream, k64u fileSize)
249 {
250  return xkTar_WriteFile(tar, itemPath, stream, fileSize);
251 }
252 
265 kInlineFx(kStatus) kTar_WriteFile(kTar tar, const kChar* itemPath, const kChar* filePath)
266 {
267  kFile file = kNULL;
268  k64u itemSize = kFile_Size(filePath);
269 
270  kTry
271  {
272  kTest(kFile_Construct(&file, filePath, kFILE_MODE_READ, kObject_Alloc(tar)));
273 
274  kTest(kTar_WriteFile(tar, itemPath, file, itemSize));
275  }
276  kFinally
277  {
278  kCheck(kObject_Destroy(file));
279 
280  kEndFinally();
281  }
282 
283  return kOK;
284 }
285 
298 {
299  return kTar_BeginWrite(tar, itemPath, kTRUE, 0);
300 }
301 
315 kInlineFx(kStatus) kTar_WriteDirectory(kTar tar, const kChar* itemPath, const kChar* directoryPath)
316 {
317  return xkTar_WriteDirectory(tar, itemPath, directoryPath);
318 }
319 
336 kFsFx(kStatus) kTar_Close(kTar tar);
337 
349 kFsFx(kStatus) kTar_BeginRead(kTar tar, kChar* itemPath, kSize itemPathCapacity, kBool* isDirectory, k64u* fileSize);
350 
364 kFsFx(kStatus) kTar_Find(kTar tar, const kChar* itemPath, kBool* isDirectory, k64u* fileSize);
365 
378 kFsFx(kStatus) kTar_ReadFile(kTar tar, const kChar* filePath, k64u fileSize);
379 
380 #endif
#define kFILE_MODE_READ
kStatus kTar_Extract(kStream source, const kChar *destParent)
Extracts a tar archive from a stream to a destination path.
Definition: kTar.h:170
Flags to control kTar operation modes.
#define kCheck(EXPRESSION)
kStatus kTar_WriteFile(kTar tar, const kChar *itemPath, kStream stream, k64u fileSize)
Adds a file to the tar archive by reading the file contents from a source stream. ...
Definition: kTar.h:248
#define kInlineFx(TYPE)
kStatus kTar_Archive(const kChar *sourcePath, kStream destStream)
Archives a file or directory to a destination stream.
Definition: kTar.h:126
#define kTest(EXPRESSION)
#define kTRUE
#define kFILE_MODE_WRITE
Essential API declarations for the kFireSync library.
#define kTry
kStatus kTar_ReadFile(kTar tar, const kChar *filePath, k64u fileSize)
Convenience method to read a file from an archive and save it to a file system path.
#define kEndFinally()
kStatus kTar_Close(kTar tar)
Closes a tar stream opened in write mode.
Class to create and extract tar archives.
kStatus kTar_Find(kTar tar, const kChar *itemPath, kBool *isDirectory, k64u *fileSize)
Convenience method to find a file or directory in an archive.
kStatus kTar_BeginRead(kTar tar, kChar *itemPath, kSize itemPathCapacity, kBool *isDirectory, k64u *fileSize)
Seeks to the next item in a kTar object opened in read mode.
#define kOK
kStatus kTar_WriteDirectory(kTar tar, const kChar *itemPath)
Adds a directory entry to an archive.
Definition: kTar.h:297
#define kNULL
#define kFinally
kStatus kTar_BeginWrite(kTar tar, const kChar *itemPath, kBool isDirectory, k64u itemSize)
Prepares a kTar object opened in write mode for the next item.
kStatus kTar_Construct(kTar *tar, kStream stream, kTarMode mode, kAlloc allocator)
Constructs a kTar object.