当前位置: 首页>>代码示例>>Golang>>正文


Golang File.Open方法代码示例

本文整理汇总了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
}
开发者ID:TimSylvester,项目名称:bitwrk,代码行数:52,代码来源:client2client.go

示例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
}
开发者ID:DaGitNah,项目名称:bitwrk,代码行数:22,代码来源:sell.go


注:本文中的github.com/indyjo/cafs.File.Open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。