// newSiphon constructs a siphoning reader that represents the passed file.
// When a successful series of reads ends in an EOF, the siphon will write
// the buffered data to Diskv's cache under the given key.
333006
func newSiphon(f *os.File, d *Diskv, key string) io.Reader {
	return &siphon{
		f:   f,
		d:   d,
		key: key,
		buf: &bytes.Buffer{},
	}
}
1241637
func (api *PublicWhisperAPI) NewSymKey(ctx context.Context) (string, error) {
	return api.w.GenerateSymKey()
}
456888
func (p Proc) NewStat() (ProcStat, error) {
	f, err := os.Open(p.path("stat"))
	if err != nil {
		return ProcStat{}, err
	}
	defer f.Close()

	data, err := ioutil.ReadAll(f)
	if err != nil {
		return ProcStat{}, err
	}

	var (
		ignore int

		s = ProcStat{PID: p.PID, fs: p.fs}
		l = bytes.Index(data, []byte("("))
		r = bytes.LastIndex(data, []byte(")"))
	)

	if l < 0 || r < 0 {
		return ProcStat{}, fmt.Errorf(
			"unexpected format, couldn't extract comm: %s",
			data,
		)
	}

	s.Comm = string(data[l+1 : r])
	_, err = fmt.Fscan(
		bytes.NewBuffer(data[r+2:]),
		&s.State,
		&s.PPID,
		&s.PGRP,
		&s.Session,
		&s.TTY,
		&s.TPGID,
		&s.Flags,
		&s.MinFlt,
		&s.CMinFlt,
		&s.MajFlt,
		&s.CMajFlt,
		&s.UTime,
		&s.STime,
		&s.CUTime,
		&s.CSTime,
		&s.Priority,
		&s.Nice,
		&s.NumThreads,
		&ignore,
		&s.Starttime,
		&s.VSize,
		&s.RSS,
	)
	if err != nil {
		return ProcStat{}, err
	}

	return s, nil
}
1251877
func (fu fileUtil) ReadByChunks(filePath string, chunkSize int, handler func(line []byte) error) error {
	var f *os.File
	var err error
	if f, err = os.Open(filePath); err == nil {
		defer f.Close()

		chunk := make([]byte, chunkSize)
		for {
			readBytes, err := f.Read(chunk)
			if err == io.EOF {
				break
			}
			readData := chunk[:readBytes]
			err = handler(readData)
			if err != nil {
				return err
			}
		}
	}
	return err
}
943045
func NewSyncPool(minSize, maxSize, factor int) *SyncPool {
	n := 0
	for chunkSize := minSize; chunkSize <= maxSize; chunkSize *= factor {
		n++
	}
	pool := &SyncPool{
		make([]sync.Pool, n),
		make([]int, n),
		minSize, maxSize,
	}
	n = 0
	for chunkSize := minSize; chunkSize <= maxSize; chunkSize *= factor {
		pool.classesSize[n] = chunkSize
		pool.classes[n].New = func(size int) func() interface{} {
			return func() interface{} {
				buf := make([]byte, size)
				return &buf
			}
		}(chunkSize)
		n++
	}
	return pool
}
1289869
func NewServer(readHandler func(filename string, rf io.ReaderFrom) error,
	writeHandler func(filename string, wt io.WriterTo) error) *Server {
	s := &Server{
		timeout:           defaultTimeout,
		retries:           defaultRetries,
		runGC:             make(chan []string),
		gcInterval:        1 * time.Minute,
		packetReadTimeout: 100 * time.Millisecond,
		readHandler:       readHandler,
		writeHandler:      writeHandler,
	}
	return s
}
286043
func NewStorage(db *sql.DB) *Storage {
	dbconn.DB.AutoMigrate(&service.Client{})
	dbconn.DB.AutoMigrate(&service.Authorize{})
	dbconn.DB.AutoMigrate(&service.Access{})
	dbconn.DB.AutoMigrate(&service.Refresh{})
	return &Storage{db}
}
1052378
func NewServer(r io.Reader, w io.Writer) *Server {
	return &Server{
		r:       NewReader(r),
		w:       NewWriter(w),
		running: atomic.NewBool(false),
	}
}
1001438
func NewStorage(dbname string, mode os.FileMode, opts *bolt.Options) Storage {
	return Storage{
		DBName: dbname,
		mode:   mode,
		opts:   opts,
	}
}
268225
func loadPipe(do func(io.Reader) error) (*io.PipeWriter, <-chan error) {
	r, w := io.Pipe()
	errc := make(chan error)
	go func() {
		progress := NewProgressCounter(300)
		progress.Log = func() { plog.Infof("Read %v bytes from archive for restore", progress.Total) }

		tr := io.TeeReader(r, progress)
		err := do(tr)
		r.CloseWithError(err)
		errc <- err
	}()
	return w, errc
}
875854
func newStreamingBitrotReader(disk StorageAPI, volume, filePath string, tillOffset int64, algo BitrotAlgorithm, shardSize int64) *streamingBitrotReader {
	h := algo.New()
	return &streamingBitrotReader{
		disk,
		nil,
		volume,
		filePath,
		ceilFrac(tillOffset, shardSize)*int64(h.Size()) + tillOffset,
		0,
		h,
		shardSize,
		make([]byte, h.Size()),
	}
}
541965
func NewShallowStorage(base, temporal storer.ShallowStorer) *ShallowStorage {
	return &ShallowStorage{
		ShallowStorer: base,
		temporal:      temporal,
	}
}
244686
func NewStoragePacker(view logical.Storage, logger log.Logger, viewPrefix string) (*StoragePacker, error) {
	if view == nil {
		return nil, fmt.Errorf("nil view")
	}

	if viewPrefix == "" {
		viewPrefix = StoragePackerBucketsPrefix
	}

	if !strings.HasSuffix(viewPrefix, "/") {
		viewPrefix = viewPrefix + "/"
	}

	// Create a new packer object for the given view
	packer := &StoragePacker{
		view:         view,
		viewPrefix:   viewPrefix,
		logger:       logger,
		storageLocks: locksutil.CreateLocks(),
	}

	return packer, nil
}
323644
func NewStream(w io.Writer) *Stream {
	return &Stream{
		Writer: w,
		enc:    json.NewEncoder(w),
	}
}
698402
func NewSyncBuffer() *SyncBuffer {
	reader, writer := io.Pipe()
	buf := &bytes.Buffer{}
	go func() {
		io.Copy(buf, reader)
	}()
	return &SyncBuffer{
		reader: reader,
		writer: writer,
		buf:    buf,
	}
}
339981
func NewSigsHandler(xp rpc.Transporter, g *libkb.GlobalContext) *SigsHandler {
	return &SigsHandler{
		BaseHandler:  NewBaseHandler(g, xp),
		Contextified: libkb.NewContextified(g),
	}
}
914820
func NewStorage(fs billy.Filesystem, cache cache.Object) *Storage {
	return NewStorageWithOptions(fs, cache, Options{})
}