本文整理匯總了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
}