1 // Copyright (c) 2012 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
6 #include "leveldb/dumpfile.h"
7 #include "leveldb/env.h"
8 #include "leveldb/status.h"
13 class StdoutPrinter
: public WritableFile
{
15 virtual Status
Append(const Slice
& data
) {
16 fwrite(data
.data(), 1, data
.size(), stdout
);
19 virtual Status
Close() { return Status::OK(); }
20 virtual Status
Flush() { return Status::OK(); }
21 virtual Status
Sync() { return Status::OK(); }
24 bool HandleDumpCommand(Env
* env
, char** files
, int num
) {
25 StdoutPrinter printer
;
27 for (int i
= 0; i
< num
; i
++) {
28 Status s
= DumpFile(env
, files
[i
], &printer
);
30 fprintf(stderr
, "%s\n", s
.ToString().c_str());
38 } // namespace leveldb
43 "Usage: leveldbutil command...\n"
44 " dump files... -- dump contents of specified files\n"
48 int main(int argc
, char** argv
) {
49 leveldb::Env
* env
= leveldb::Env::Default();
55 std::string command
= argv
[1];
56 if (command
== "dump") {
57 ok
= leveldb::HandleDumpCommand(env
, argv
+2, argc
-2);