This commit is contained in:
Colin Marc 2014-10-05 18:58:46 +02:00
Родитель ac6255ea47
Коммит f25c4cbbe5
2 изменённых файлов: 192 добавлений и 0 удалений

112
file.go Normal file
Просмотреть файл

@ -0,0 +1,112 @@
package hdfs
import "os"
const clientName = "go-hdfs"
// HdfsFile represents a file or directory in HDFS. It implements the Writer,
// SectionReader, and Closer interfaces, but not SectionWriter or Seeker.
type HdfsFile struct {
name string
closed bool
}
// Open returns an HdfsFile which can be used for reading.
func Open(name string) (file *HdfsFile, err error) {
return &HdfsFile{name, true}, nil
}
// Create creates the named file, overwriting it if it already exists.
// The file can then be used for reading and writing.
func Create(name string, perm os.FileMode) (file *HdfsFile, err error) {
return &HdfsFile{name, true}, nil
}
// Name returns the name of the file.
func (f *HdfsFile) Name() string {
return f.name
}
// Read reads up to len(b) bytes from the HdfsFile. It returns the number of bytes
// read and an error, if any. EOF is signaled by a zero count with err set to
// io.EOF.
func (f *HdfsFile) Read(b []byte) (n int, err error) {
return 0, nil
}
// ReadAt reads len(b) bytes from the HdfsFile starting at byte offset off. It
// returns the number of bytes read and the error, if any. ReadAt always returns
// a non-nil error when n < len(b). At end of file, that error is io.EOF.
func (f *HdfsFile) ReadAt(b []byte, off int64) (n int, err error) {
return 0, nil
}
// Readdir reads the contents of the directory associated with file and returns
// a slice of up to n os.FileInfo values, as would be returned by Stat, in
// directory order. Subsequent calls on the same file will yield further
// os.FileInfos.
//
// If n > 0, Readdir returns at most n os.FileInfo values. In this case, if
// Readdir returns an empty slice, it will return a non-nil error explaining
// why. At the end of a directory, the error is io.EOF.
//
// If n <= 0, Readdir returns all the os.FileInfo from the directory in a single
// slice. In this case, if Readdir succeeds (reads all the way to the end of
// the directory), it returns the slice and a nil error. If it encounters an
// error before the end of the directory, Readdir returns the os.FileInfo read
// until that point and a non-nil error.
func (f *HdfsFile) Readdir(n int) (fi []os.FileInfo, err error) {
return []os.FileInfo{}, nil
}
// Readdirnames reads and returns a slice of names from the directory f.
//
// If n > 0, Readdirnames returns at most n names. In this case, if Readdirnames
// returns an empty slice, it will return a non-nil error explaining why. At the
// end of a directory, the error is io.EOF.
//
// If n <= 0, Readdirnames returns all the names from the directory in a single
// slice. In this case, if Readdirnames succeeds (reads all the way to the end
// of the directory), it returns the slice and a nil error. If it encounters an
// error before the end of the directory, Readdirnames returns the names read
// until that point and a non-nil error.
func (f *HdfsFile) Readdirnames(n int) (names []string, err error) {
return []string{}, nil
}
// Write writes len(b) bytes to the HdfsFile. It returns the number of bytes written
// and an error, if any. Write returns a non-nil error when n != len(b).
//
// Unlike a regular os.File, the contents will be buffered into memory
func (f *HdfsFile) Write(b []byte) (n int, err error) {
return 0, nil
}
// WriteAt writes len(b) bytes to the HdfsFile starting at byte offset off.
// It returns the number of bytes written and an error, if any. WriteAt returns
// a non-nil error when n != len(b).
func (f *HdfsFile) WriteAt(b []byte, off int64) (n int, err error) {
return 0, nil
}
// WriteString is like Write, but writes the contents of string s rather than a
// slice of bytes.
func (f *HdfsFile) WriteString(s string) (ret int, err error) {
return 0, nil
}
// Chmod changes the mode of the file to mode.
func (f *HdfsFile) Chmod(mode os.FileMode) error {
return nil
}
// Chown changes the numeric uid and gid of the named file.
func (f *HdfsFile) Chown(uid, gid int) error {
return nil
}
// Close closes the HdfsFile.
func (f *HdfsFile) Close() error {
return nil
}

80
hdfs.go Normal file
Просмотреть файл

@ -0,0 +1,80 @@
package hdfs
import "os"
// Represents a connection to an HDFS Namenode
type Client struct {
namenode string
}
// New returns a connected Client, or an error if it can't connect
func New(namenode string) (*Client, error) {
return &Client{namenode}, nil
}
// Chmod changes the mode of the named file to mode.
func (c *Client) Chmod(name string, mode os.FileMode) error {
return nil
}
// Chown changes the numeric uid and gid of the named file.
func (c *Client) Chown(name string, uid, gid int) error {
return nil
}
// Mkdir creates a new directory with the specified name and permission bits.
func (c *Client) Mkdir(name string, perm os.FileMode) error {
return nil
}
// MkdirAll creates a directory named path, along with any necessary parents,
// and returns nil, or else returns an error. The permission bits perm are used
// for all directories that MkdirAll creates. If path is already a directory,
// MkdirAll does nothing and returns nil.
func (c *Client) MkdirAll(path string, perm os.FileMode) error {
return nil
}
// Remove removes the named file or directory.
func (c *Client) Remove(name string) error {
return nil
}
// Rename renames (moves) a file.
func (c *Client) Rename(oldpath, newpath string) error {
return nil
}
// Stat returns an os.FileInfo describing the named file.
func (c *Client) Stat(name string) (fi os.FileInfo, err error) {
return nil, nil
}
// ReadDir reads the directory named by dirname and returns a list of sorted
// directory entries.
func ReadDir(dirname string) ([]os.FileInfo, error) {
return []os.FileInfo{}, nil
}
// ReadFile reads the file named by filename and returns the contents.
func ReadFile(filename string) ([]byte, error) {
return []byte{}, nil
}
// WriteFile writes data to a file named by filename. If the file already
// exists, it will be overwritten
func WriteFile(filename string, data []byte, perm os.FileMode) error {
return nil
}
// CopyToLocal copies the HDFS file specified by src to the local file at dst.
// If dst already exists, it will be overwritten.
func CopyToLocal(src string, dst string, perm os.FileMode) error {
return nil
}
// CopyToHdfs copies the local file at src to a new HDFS file at dst. If it
// already exists, it will be overwritten.
func CopyToHdfs(src string, dst string, perm os.FileMode) error {
return nil
}