2024-05-14 18:37:41 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package fileservice
|
|
|
|
|
|
|
|
import (
|
2024-05-14 21:29:41 +02:00
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
2024-05-14 18:37:41 +02:00
|
|
|
"os"
|
2024-05-14 21:29:41 +02:00
|
|
|
"time"
|
2024-05-14 18:37:41 +02:00
|
|
|
|
|
|
|
"github.com/wavetermdev/thenextwave/pkg/wavebase"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FileService struct{}
|
|
|
|
|
2024-05-14 21:29:41 +02:00
|
|
|
func (fs *FileService) ReadFile(path string) (string, error) {
|
2024-05-14 18:37:41 +02:00
|
|
|
path = wavebase.ExpandHomeDir(path)
|
2024-05-14 21:29:41 +02:00
|
|
|
barr, err := os.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("cannot read file %q: %w", path, err)
|
|
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
return base64.StdEncoding.EncodeToString(barr), nil
|
2024-05-14 18:37:41 +02:00
|
|
|
}
|