github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/storage/noop.go (about)

     1  // Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
     2  
     3  package storage
     4  
     5  import (
     6  	"context"
     7  )
     8  
     9  type noopStorage struct{}
    10  
    11  // WriteFile file to storage.
    12  func (*noopStorage) WriteFile(ctx context.Context, name string, data []byte) error {
    13  	return nil
    14  }
    15  
    16  // ReadFile storage file.
    17  func (*noopStorage) ReadFile(ctx context.Context, name string) ([]byte, error) {
    18  	return []byte{}, nil
    19  }
    20  
    21  // FileExists return true if file exists.
    22  func (*noopStorage) FileExists(ctx context.Context, name string) (bool, error) {
    23  	return false, nil
    24  }
    25  
    26  // Open a Reader by file path.
    27  func (*noopStorage) Open(ctx context.Context, path string) (ExternalFileReader, error) {
    28  	return noopReader{}, nil
    29  }
    30  
    31  // WalkDir traverse all the files in a dir.
    32  func (*noopStorage) WalkDir(ctx context.Context, opt *WalkOption, fn func(string, int64) error) error {
    33  	return nil
    34  }
    35  
    36  func (s *noopStorage) URI() string {
    37  	return "noop:///"
    38  }
    39  
    40  // Create implements ExternalStorage interface.
    41  func (*noopStorage) Create(ctx context.Context, name string) (ExternalFileWriter, error) {
    42  	return &noopWriter{}, nil
    43  }
    44  
    45  func newNoopStorage() *noopStorage {
    46  	return &noopStorage{}
    47  }
    48  
    49  type noopReader struct{}
    50  
    51  func (noopReader) Read(p []byte) (n int, err error) {
    52  	return len(p), nil
    53  }
    54  
    55  func (noopReader) Close() error {
    56  	return nil
    57  }
    58  
    59  func (noopReader) Seek(offset int64, whence int) (int64, error) {
    60  	return offset, nil
    61  }
    62  
    63  type noopWriter struct{}
    64  
    65  func (noopWriter) Write(ctx context.Context, p []byte) (int, error) {
    66  	return len(p), nil
    67  }
    68  
    69  func (noopWriter) Close(ctx context.Context) error {
    70  	return nil
    71  }