MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / WriteBytes

Method WriteBytes

internal/plugins/plugins.go:390–414  ·  view source on GitHub ↗
(identifier string, bytes []byte)

Source from the content-addressed store, hash-verified

388}
389
390func (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
416func (p *Plugin) ReadBytes(identifier string) ([]byte, error) {
417

Calls 4

FilePathFunction · 0.92
ErrorFunction · 0.92
WriteFileFunction · 0.92
StatMethod · 0.45