file

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 5 Imported by: 0

README

File (文件)

提供简单的文件读写辅助功能。

API

ReadRemoteFile
  • 签名: func ReadRemoteFile(url string) ([]byte, error)
  • 描述: 读取远程 URL 的文件内容。
  • 注意: 全量加载到内存,不适合大文件。
WriteLocalFile
  • 签名: func WriteLocalFile(path string, bytes []byte) error
  • 描述: 将字节内容写入本地文件。
  • 特性: 自动创建缺失的目录,覆盖已存在的文件。

示例

import (
    "fmt"
    "github.com/fireflycore/go-utils/file"
)

func main() {
    // 读取远程
    data, err := file.ReadRemoteFile("https://example.com/data.json")
    if err != nil {
        panic(err)
    }

    // 写入本地
    err = file.WriteLocalFile("./data/backup.json", data)
    if err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadRemoteFile

func ReadRemoteFile(url string) ([]byte, error)

ReadRemoteFile 读取远程文件内容 url: 远程文件的 URL 地址 返回: 文件内容的字节切片。如果下载失败或读取失败,返回 error 注意:此函数会将整个文件加载到内存,不适合读取大文件

func WriteLocalFile

func WriteLocalFile(path string, bytes []byte) error

WriteLocalFile 将内容写入本地文件 path: 本地文件路径(包含文件名) bytes: 要写入的字节内容 返回: 错误信息 注意: 如果目录不存在,会自动创建;如果文件已存在,会覆盖

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL