| 388 | } |
| 389 | |
| 390 | func (p *Plugin) WriteBytes(identifier string, bytes []byte) error { |
| 391 | |
| 392 | // Fix up identifier |
| 393 | fileName := strings.ToLower(txtCleanRegex.ReplaceAllString(identifier, "-")) + `.plugin.dat` |
| 394 | |
| 395 | // Fix up folderpath |
| 396 | folderPath := util.FilePath(writeFolderPath, `/`, strings.ToLower(txtCleanRegex.ReplaceAllString(fmt.Sprintf(`%s-v%s`, p.name, p.version), "-"))) |
| 397 | |
| 398 | // Create full path |
| 399 | fullPath := util.FilePath(folderPath, `/`, fileName) |
| 400 | |
| 401 | if _, err := os.Stat(fullPath); err != nil { |
| 402 | if err = os.MkdirAll(folderPath, 0777); err != nil { |
| 403 | mudlog.Error(`plugin.WriteBytes`, `name`, p.name, `path`, folderPath, `error`, err) |
| 404 | return err |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | if err := util.WriteFile(fullPath, bytes, 0777); err != nil { |
| 409 | mudlog.Error(`plugin.WriteBytes`, `name`, p.name, `path`, fullPath, `error`, err) |
| 410 | return err |
| 411 | } |
| 412 | |
| 413 | return nil |
| 414 | } |
| 415 | |
| 416 | func (p *Plugin) ReadBytes(identifier string) ([]byte, error) { |
| 417 | |