Skip to content

Commit

Permalink
Move filesys.h into io.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jan 9, 2019
1 parent e946b65 commit 5ca863a
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 134 deletions.
1 change: 1 addition & 0 deletions include/dmlc/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define DMLC_FILESYSTEM_H_

#include <dmlc/logging.h>
#include <dmlc/io.h>
#include <algorithm>
#include <string>
#include <vector>
Expand Down
114 changes: 114 additions & 0 deletions include/dmlc/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define DMLC_IO_H_
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <istream>
#include <ostream>
Expand Down Expand Up @@ -518,5 +519,118 @@ inline int istream::InBuf::underflow() {
}
}
#endif

namespace io {
/*! \brief common data structure for URI */
struct URI {
/*! \brief protocol */
std::string protocol;
/*!
* \brief host name, namenode for HDFS, bucket name for s3
*/
std::string host;
/*! \brief name of the path */
std::string name;
/*! \brief enable default constructor */
URI(void) {}
/*!
* \brief construct from URI string
*/
explicit URI(const char *uri) {
const char *p = std::strstr(uri, "://");
if (p == NULL) {
name = uri;
} else {
protocol = std::string(uri, p - uri + 3);
uri = p + 3;
p = std::strchr(uri, '/');
if (p == NULL) {
host = uri; name = '/';
} else {
host = std::string(uri, p - uri);
name = p;
}
}
}
/*! \brief string representation */
inline std::string str(void) const {
return protocol + host + name;
}
};

/*! \brief type of file */
enum FileType {
/*! \brief the file is file */
kFile,
/*! \brief the file is directory */
kDirectory
};

/*! \brief use to store file information */
struct FileInfo {
/*! \brief full path to the file */
URI path;
/*! \brief the size of the file */
size_t size;
/*! \brief the type of the file */
FileType type;
/*! \brief default constructor */
FileInfo() : size(0), type(kFile) {}
};

/*! \brief file system system interface */
class FileSystem {
public:
/*!
* \brief get singleton of filesystem instance according to URI
* \param path can be s3://..., hdfs://..., file://...,
* empty string(will return local)
* \return a corresponding filesystem, report error if
* we cannot find a matching system
*/
static FileSystem *GetInstance(const URI &path);
/*! \brief virtual destructor */
virtual ~FileSystem() {}
/*!
* \brief get information about a path
* \param path the path to the file
* \return the information about the file
*/
virtual FileInfo GetPathInfo(const URI &path) = 0;
/*!
* \brief list files in a directory
* \param path to the file
* \param out_list the output information about the files
*/
virtual void ListDirectory(const URI &path, std::vector<FileInfo> *out_list) = 0;
/*!
* \brief list files in a directory recursively using ListDirectory
* \param path to the file
* \param out_list the output information about the files
*/
virtual void ListDirectoryRecursive(const URI &path,
std::vector<FileInfo> *out_list);
/*!
* \brief open a stream
* \param path path to file
* \param uri the uri of the input, can contain hdfs prefix
* \param flag can be "w", "r", "a
* \param allow_null whether NULL can be returned, or directly report error
* \return the created stream, can be NULL when allow_null == true and file do not exist
*/
virtual Stream *Open(const URI &path,
const char* const flag,
bool allow_null = false) = 0;
/*!
* \brief open a seekable stream for read
* \param path the path to the file
* \param allow_null whether NULL can be returned, or directly report error
* \return the created stream, can be NULL when allow_null == true and file do not exist
*/
virtual SeekStream *OpenForRead(const URI &path,
bool allow_null = false) = 0;
};

} // namespace io
} // namespace dmlc
#endif // DMLC_IO_H_
1 change: 0 additions & 1 deletion src/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "io/recordio_split.h"
#include "io/indexed_recordio_split.h"
#include "io/single_file_split.h"
#include "io/filesys.h"
#include "io/local_filesys.h"
#include "io/cached_input_split.h"
#include "io/threaded_input_split.h"
Expand Down
2 changes: 0 additions & 2 deletions src/io/filesys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include <queue>
#include <dmlc/filesystem.h>

#include "./filesys.h"

namespace dmlc {
namespace io {

Expand Down
128 changes: 0 additions & 128 deletions src/io/filesys.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/io/input_split_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#define DMLC_IO_INPUT_SPLIT_BASE_H_

#include <dmlc/io.h>
#include <dmlc/filesystem.h>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include "./filesys.h"

namespace dmlc {
namespace io {
Expand Down
2 changes: 1 addition & 1 deletion src/io/local_filesys.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define DMLC_IO_LOCAL_FILESYS_H_

#include <vector>
#include "./filesys.h"
#include <dmlc/filesystem.h>

namespace dmlc {
namespace io {
Expand Down
1 change: 0 additions & 1 deletion src/io/uri_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <map>
#include <vector>
#include <utility>
#include "./filesys.h"

namespace dmlc {
namespace io {
Expand Down

0 comments on commit 5ca863a

Please sign in to comment.