Skip to content

Commit

Permalink
file/files: fixing a bug in Get File where we'd try and unmarshal t…
Browse files Browse the repository at this point in the history
…he file
  • Loading branch information
tombuildsstuff committed Apr 5, 2024
1 parent 29e7fd4 commit bbf0f64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 13 additions & 5 deletions storage/2023-11-03/file/files/range_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package files
import (
"context"
"fmt"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -83,13 +85,19 @@ func (c Client) GetByteRange(ctx context.Context, shareName, path, fileName stri
var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil && resp.Response != nil {
result.Contents = &[]byte{}
result.HttpResponse = resp.Response

err = resp.Unmarshal(result.Contents)
if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
result.Contents = &[]byte{}
if resp.Body != nil {
respBody, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return result, fmt.Errorf("could not parse response body")
}

if respBody != nil {
result.Contents = pointer.To(respBody)
}
}
}
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions storage/2023-11-03/file/files/range_get_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func (c Client) GetFile(ctx context.Context, shareName, path, fileName string, i
copy(output[v.startBytes:v.endBytes], *v.bytes)
}

if result.OutputBytes == nil {
result.OutputBytes = &[]byte{}
}
*result.OutputBytes = output
return
}
Expand Down

0 comments on commit bbf0f64

Please sign in to comment.