refactor(tvix/nar-bridge): move blob cb function to pkg/importer
This is useful outside a HTTP server scenario. Change-Id: If35f1ab245855378fd01f16ad7b5774d0cf590ba Reviewed-on: https://cl.tvl.fyi/c/depot/+/9532 Tested-by: BuildkiteCI Reviewed-by: Connor Brewster <cbrewster@hey.com> Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
		
							parent
							
								
									259269482c
								
							
						
					
					
						commit
						b78b8d8338
					
				
					 2 changed files with 3 additions and 3 deletions
				
			
		|  | @ -1,4 +1,4 @@ | ||||||
| package server | package importer | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"bufio" | 	"bufio" | ||||||
|  | @ -17,7 +17,7 @@ const chunkSize = 1024 * 1024 | ||||||
| 
 | 
 | ||||||
| // this produces a callback function that can be used as blobCb for the | // this produces a callback function that can be used as blobCb for the | ||||||
| // importer.Import function call. | // importer.Import function call. | ||||||
| func genBlobServiceWriteCb(ctx context.Context, blobServiceClient castorev1pb.BlobServiceClient) func(io.Reader) ([]byte, error) { | func GenBlobUploaderCb(ctx context.Context, blobServiceClient castorev1pb.BlobServiceClient) func(io.Reader) ([]byte, error) { | ||||||
| 	return func(blobReader io.Reader) ([]byte, error) { | 	return func(blobReader io.Reader) ([]byte, error) { | ||||||
| 		// Ensure the blobReader is buffered to at least the chunk size. | 		// Ensure the blobReader is buffered to at least the chunk size. | ||||||
| 		blobReader = bufio.NewReaderSize(blobReader, chunkSize) | 		blobReader = bufio.NewReaderSize(blobReader, chunkSize) | ||||||
|  | @ -43,7 +43,7 @@ func registerNarPut(s *Server) { | ||||||
| 			ctx, | 			ctx, | ||||||
| 			// buffer the body by 10MiB | 			// buffer the body by 10MiB | ||||||
| 			bufio.NewReaderSize(r.Body, 10*1024*1024), | 			bufio.NewReaderSize(r.Body, 10*1024*1024), | ||||||
| 			genBlobServiceWriteCb(ctx, s.blobServiceClient), | 			importer.GenBlobUploaderCb(ctx, s.blobServiceClient), | ||||||
| 			func(directory *castorev1pb.Directory) ([]byte, error) { | 			func(directory *castorev1pb.Directory) ([]byte, error) { | ||||||
| 				return directoriesUploader.Put(directory) | 				return directoriesUploader.Put(directory) | ||||||
| 			}, | 			}, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue