mirror of https://github.com/Xhofe/alist
				
				
				
			
		
			
				
	
	
		
			37 lines
		
	
	
		
			706 B
		
	
	
	
		
			Go
		
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			706 B
		
	
	
	
		
			Go
		
	
	
| // Credits: https://pkg.go.dev/github.com/rclone/rclone@v1.65.2/cmd/serve/s3
 | |
| // Package s3 implements a fake s3 server for alist
 | |
| package s3
 | |
| 
 | |
| import "io"
 | |
| 
 | |
| type noOpReadCloser struct{}
 | |
| 
 | |
| type readerWithCloser struct {
 | |
| 	io.Reader
 | |
| 	closer func() error
 | |
| }
 | |
| 
 | |
| var _ io.ReadCloser = &readerWithCloser{}
 | |
| 
 | |
| func (d noOpReadCloser) Read(b []byte) (n int, err error) {
 | |
| 	return 0, io.EOF
 | |
| }
 | |
| 
 | |
| func (d noOpReadCloser) Close() error {
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| func limitReadCloser(rdr io.Reader, closer func() error, sz int64) io.ReadCloser {
 | |
| 	return &readerWithCloser{
 | |
| 		Reader: io.LimitReader(rdr, sz),
 | |
| 		closer: closer,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (rwc *readerWithCloser) Close() error {
 | |
| 	if rwc.closer != nil {
 | |
| 		return rwc.closer()
 | |
| 	}
 | |
| 	return nil
 | |
| }
 |