mirror of https://github.com/google/snappy.git
Adjust the Snappy open-source distribution for the changes in Google's
internal file API. R=sanjay git-svn-id: https://snappy.googlecode.com/svn/trunk@70 03e5f5b5-db94-4691-08a0-1a8bf15f6143
This commit is contained in:
parent
698af469b4
commit
81f34784b7
|
@ -46,10 +46,13 @@ string ReadTestDataFile(const string& base) {
|
||||||
string contents;
|
string contents;
|
||||||
const char* srcdir = getenv("srcdir"); // This is set by Automake.
|
const char* srcdir = getenv("srcdir"); // This is set by Automake.
|
||||||
if (srcdir) {
|
if (srcdir) {
|
||||||
File::ReadFileToStringOrDie(
|
file::ReadFileToString(string(srcdir) + "/testdata/" + base,
|
||||||
string(srcdir) + "/testdata/" + base, &contents);
|
&contents,
|
||||||
|
file::Defaults()).CheckSuccess();
|
||||||
} else {
|
} else {
|
||||||
File::ReadFileToStringOrDie("testdata/" + base, &contents);
|
file::ReadFileToString("/testdata/" + base,
|
||||||
|
&contents,
|
||||||
|
file::Defaults()).CheckSuccess();
|
||||||
}
|
}
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,10 +126,20 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
namespace File {
|
namespace File {
|
||||||
void Init() { }
|
void Init() { }
|
||||||
|
} // namespace File
|
||||||
|
|
||||||
void ReadFileToStringOrDie(const char* filename, string* data) {
|
namespace file {
|
||||||
|
int Defaults() { }
|
||||||
|
|
||||||
|
class DummyStatus {
|
||||||
|
public:
|
||||||
|
void CheckSuccess() { }
|
||||||
|
};
|
||||||
|
|
||||||
|
DummyStatus ReadFileToString(const char* filename, string* data, int unused) {
|
||||||
FILE* fp = fopen(filename, "rb");
|
FILE* fp = fopen(filename, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
perror(filename);
|
perror(filename);
|
||||||
|
@ -150,14 +160,18 @@ namespace File {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadFileToStringOrDie(const string& filename, string* data) {
|
DummyStatus ReadFileToString(const string& filename,
|
||||||
ReadFileToStringOrDie(filename.c_str(), data);
|
string* data,
|
||||||
|
int unused) {
|
||||||
|
ReadFileToString(filename.c_str(), data, unused);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteStringToFileOrDie(const string& str, const char* filename) {
|
DummyStatus WriteStringToFile(const string& str,
|
||||||
FILE* fp = fopen(filename, "wb");
|
const string& filename,
|
||||||
|
int unused) {
|
||||||
|
FILE* fp = fopen(filename.c_str(), "wb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
perror(filename);
|
perror(filename.c_str());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +183,8 @@ namespace File {
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
} // namespace File
|
} // namespace file
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace snappy {
|
namespace snappy {
|
||||||
|
|
|
@ -971,18 +971,19 @@ TEST(Snappy, FindMatchLengthRandom) {
|
||||||
|
|
||||||
static void CompressFile(const char* fname) {
|
static void CompressFile(const char* fname) {
|
||||||
string fullinput;
|
string fullinput;
|
||||||
File::ReadFileToStringOrDie(fname, &fullinput);
|
file::ReadFileToString(fname, &fullinput, file::Defaults()).CheckSuccess();
|
||||||
|
|
||||||
string compressed;
|
string compressed;
|
||||||
Compress(fullinput.data(), fullinput.size(), SNAPPY, &compressed, false);
|
Compress(fullinput.data(), fullinput.size(), SNAPPY, &compressed, false);
|
||||||
|
|
||||||
File::WriteStringToFileOrDie(compressed,
|
file::WriteStringToFile(
|
||||||
string(fname).append(".comp").c_str());
|
string(fname).append(".comp").c_str(), compressed,
|
||||||
|
file::Defaults()).CheckSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UncompressFile(const char* fname) {
|
static void UncompressFile(const char* fname) {
|
||||||
string fullinput;
|
string fullinput;
|
||||||
File::ReadFileToStringOrDie(fname, &fullinput);
|
file::ReadFileToString(fname, &fullinput, file::Defaults()).CheckSuccess();
|
||||||
|
|
||||||
size_t uncompLength;
|
size_t uncompLength;
|
||||||
CHECK(CheckUncompressedLength(fullinput, &uncompLength));
|
CHECK(CheckUncompressedLength(fullinput, &uncompLength));
|
||||||
|
@ -991,13 +992,14 @@ static void UncompressFile(const char* fname) {
|
||||||
uncompressed.resize(uncompLength);
|
uncompressed.resize(uncompLength);
|
||||||
CHECK(snappy::Uncompress(fullinput.data(), fullinput.size(), &uncompressed));
|
CHECK(snappy::Uncompress(fullinput.data(), fullinput.size(), &uncompressed));
|
||||||
|
|
||||||
File::WriteStringToFileOrDie(uncompressed,
|
file::WriteStringToFile(
|
||||||
string(fname).append(".uncomp").c_str());
|
string(fname).append(".uncomp").c_str(), uncompressed,
|
||||||
|
file::Defaults()).CheckSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MeasureFile(const char* fname) {
|
static void MeasureFile(const char* fname) {
|
||||||
string fullinput;
|
string fullinput;
|
||||||
File::ReadFileToStringOrDie(fname, &fullinput);
|
file::ReadFileToString(fname, &fullinput, file::Defaults()).CheckSuccess();
|
||||||
printf("%-40s :\n", fname);
|
printf("%-40s :\n", fname);
|
||||||
|
|
||||||
int start_len = (FLAGS_start_len < 0) ? fullinput.size() : FLAGS_start_len;
|
int start_len = (FLAGS_start_len < 0) ? fullinput.size() : FLAGS_start_len;
|
||||||
|
|
Loading…
Reference in New Issue