Bug 1154435 - [nsGZFileWriter] Add one more mode for writing a GZFile (Create/Append). r=froydnj

This commit is contained in:
Alphan Chen 2015-06-05 11:20:16 +08:00
parent 310eaefd94
commit 051f87490e
2 changed files with 15 additions and 5 deletions

View File

@ -18,8 +18,9 @@
NS_IMPL_ISUPPORTS(nsGZFileWriter, nsIGZFileWriter)
nsGZFileWriter::nsGZFileWriter()
: mInitialized(false)
nsGZFileWriter::nsGZFileWriter(Operation aMode)
: mMode(aMode)
, mInitialized(false)
, mFinished(false)
{
}
@ -43,7 +44,8 @@ nsGZFileWriter::Init(nsIFile* aFile)
// gzip can own. Then close our FILE, leaving only gzip's fd open.
FILE* file;
nsresult rv = aFile->OpenANSIFileDesc("wb", &file);
nsresult rv = aFile->OpenANSIFileDesc(mMode == Create ? "wb" : "ab", &file);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -53,7 +55,7 @@ nsGZFileWriter::Init(nsIFile* aFile)
NS_IMETHODIMP
nsGZFileWriter::InitANSIFileDesc(FILE* aFile)
{
mGZFile = gzdopen(dup(fileno(aFile)), "wb");
mGZFile = gzdopen(dup(fileno(aFile)), mMode == Create ? "wb" : "ab");
fclose(aFile);
// gzdopen returns nullptr on error.

View File

@ -18,7 +18,14 @@ class nsGZFileWriter final : public nsIGZFileWriter
virtual ~nsGZFileWriter();
public:
nsGZFileWriter();
enum Operation {
Append,
Create
};
explicit nsGZFileWriter(Operation aMode = Create);
NS_DECL_ISUPPORTS
NS_DECL_NSIGZFILEWRITER
@ -39,6 +46,7 @@ public:
}
private:
Operation mMode;
bool mInitialized;
bool mFinished;
gzFile mGZFile;