go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/connection/container/cache/stream.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package cache
     5  
     6  import (
     7  	"io"
     8  	"os"
     9  )
    10  
    11  func RandomFile() (*os.File, error) {
    12  	return os.CreateTemp("", "mondoo.inspection")
    13  }
    14  
    15  // This streams a binary stream into a file. The user of this method
    16  // is responsible for deleting the file late
    17  func StreamToTmpFile(r io.ReadCloser, outFile *os.File) error {
    18  	defer outFile.Close()
    19  	_, err := io.Copy(outFile, r)
    20  	if err != nil {
    21  		return err
    22  	}
    23  
    24  	return r.Close()
    25  }