本文整理汇总了Golang中github.com/indyjo/cafs.File.Open方法的典型用法代码示例。如果您正苦于以下问题:Golang File.Open方法的具体用法?Golang File.Open怎么用?Golang File.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/indyjo/cafs.File
的用法示例。
在下文中一共展示了File.Open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: dispatchWorkAndSaveEncryptedResult
func (a *SellActivity) dispatchWorkAndSaveEncryptedResult(log bitwrk.Logger, workFile cafs.File) error {
// Watch transaction state and close connection to worker when transaction expires
connChan := make(chan io.Closer)
exitChan := make(chan bool)
go a.watchdog(log, exitChan, connChan, func() bool { return a.tx.State == bitwrk.StateActive })
defer func() {
exitChan <- true
}()
st := NewScopedTransport()
connChan <- st
defer st.Close()
reader := workFile.Open()
defer reader.Close()
result, err := a.worker.DoWork(reader, NewClient(&st.Transport))
if err != nil {
return err
}
defer result.Close()
temp := a.manager.storage.Create(fmt.Sprintf("Sell #%v: encrypted result", a.GetKey()))
defer temp.Dispose()
// Use AES-256 to encrypt the result
block, err := aes.NewCipher(a.encResultKey[:])
if err != nil {
return err
}
// Create OFB stream with null initialization vector (ok for one-time key)
var iv [aes.BlockSize]byte
stream := cipher.NewOFB(block, iv[:])
writer := &cipher.StreamWriter{S: stream, W: temp}
_, err = io.Copy(writer, result)
if err != nil {
return err
}
if err := temp.Close(); err != nil {
return err
}
if err := result.Close(); err != nil {
return err
}
a.execSync(func() { a.encResultFile = temp.File() })
return nil
}
示例2: dispatchWork
func (a *SellActivity) dispatchWork(log bitwrk.Logger, workFile cafs.File) (io.ReadCloser, error) {
// Watch transaction state and close connection to worker when transaction expires
connChan := make(chan io.Closer)
exitChan := make(chan bool)
go a.watchdog(log, exitChan, connChan, func() bool { return a.tx.State == bitwrk.StateActive })
defer func() {
exitChan <- true
}()
reader := workFile.Open()
defer reader.Close()
st := NewScopedTransport()
connChan <- st
defer st.Close()
r, err := a.worker.DoWork(reader, NewClient(&st.Transport))
if err == nil {
// Defuse connection closing mechanism
st.DisownConnections()
}
return r, err
}