repo_description: 视频号、小程序、抖音、快手、小红书、直播流、m3u8、酷狗、QQ音乐等常见网络资源下载!
repo_topics: douyin kuaishou res-downloader wechat wechat-video xiaohongshu
code: package core
  
  import (
  	"os"
  	"path"
  	"res-downloader/core/shared"
  )
  
  type Storage struct {
  	fileName string
  	def      []byte
  }
  
  func NewStorage(filename string, def []byte) *Storage {
  	return &Storage{
  		fileName: path.Join(appOnce.UserDir, filename),
  		def:      def,
  	}
  }
  
  func (l *Storage) Load() ([]byte, error) {
  	if !shared.FileExist(l.fileName) {
  		err := os.WriteFile(l.fileName, l.def, 0644)
  		if err != nil {
  			return nil, err
  		}
  		return l.def, nil
  	}
  	d, err := os.ReadFile(l.fileName)
  	if err != nil {
  		return nil, err
  	}
  	return d, err
  }
  
  func (l *Storage) Store(data []byte) error {
  	if err := os.WriteFile(l.fileName, data, 0644); err != nil {
  		return err
  	}
  	return nil
  }
  