// NewBufferStore creates a BufferStore using r for read.
13940
func NewBufferStore(r Retriever, cap int) *BufferStore {
	if cap <= 0 {
		cap = DefaultTxnMembufCap
	}
	return &BufferStore{
		r:         r,
		MemBuffer: &lazyMemBuffer{cap: cap},
	}
}
118177
func NewBufferedReader(size int) ReaderMiddleware {
    return func(readCloser io.ReadCloser) io.ReadCloser {
        return &ReadCombiner{bufio.NewReaderSize(readCloser, size), readCloser}
    }
}
920108
func NewIndexStorage(s, temporal storer.IndexStorer) *IndexStorage {
	return &IndexStorage{
		IndexStorer: s,
		temporal:    temporal,
	}
}
571864
func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore {
	keydir, _ = filepath.Abs(keydir)
	ks := &KeyStore{storage: &keyStorePassphrase{keydir, scryptN, scryptP, false}}
	ks.init(keydir)
	return ks
}
1121921
func NewDataStore(scope string, cfg *ScopeCfg) (DataStore, error) {
	if cfg == nil || cfg.Client.Provider == "" || cfg.Client.Address == "" {
		c, ok := defaultScopes[scope]
		if !ok || c.Client.Provider == "" || c.Client.Address == "" {
			return nil, fmt.Errorf("unexpected scope %s without configuration passed", scope)
		}

		cfg = c
	}

	var cached bool
	if scope == LocalScope {
		cached = true
	}

	return newClient(scope, cfg.Client.Provider, cfg.Client.Address, cfg.Client.Config, cached)
}
820844
func NewDBStore(path string) (s *DBStore, err error) {
	db, err := leveldb.OpenFile(path, nil)
	if err != nil {
		return nil, err
	}
	return &DBStore{
		db: db,
	}, nil
}
1303485
func NewRingBuffer(
	capacity int,
	consolidateFunc MsgConsolidateFunc) *RingBuffer {
	return &RingBuffer{
		consolidateFunc: consolidateFunc,
		next:            0,
		msgs:            make([]Msg, capacity),
	}
}
1220345
func NewBufferAttr() *BufferAttr {
	return &BufferAttr{
		Maxlength: ^uint32(0),
		Tlength:   ^uint32(0),
		Prebuf:    ^uint32(0),
		Minreq:    ^uint32(0),
		Fragsize:  ^uint32(0),
	}
}
529295
func newBuffer(nc net.Conn) buffer {
	fg := make([]byte, defaultBufSize)
	return buffer{
		buf:  fg,
		nc:   nc,
		dbuf: [2][]byte{fg, nil},
	}
}
313765
func (fs *FileStore) newFileSubStore(channel string, limits *SubStoreLimits, doRecover bool) (*FileSubStore, error) {
	ss := &FileSubStore{
		fstore:   fs,
		fm:       fs.fm,
		opts:     &fs.opts,
		crcTable: fs.crcTable,
	}
	ss.init(fs.log, limits)
	// Convert the CompactInterval in time.Duration
	ss.compactItvl = time.Duration(ss.opts.CompactInterval) * time.Second

	var err error

	fileName := filepath.Join(channel, subsFileName)
	ss.file, err = fs.fm.createFile(fileName, defaultFileFlags, func() error {
		ss.writer = nil
		return ss.flush()
	})
	if err != nil {
		return nil, err
	}
	maxBufSize := ss.opts.BufferSize
	ss.writer = ss.file.handle
	// If we allow buffering, then create the buffered writer and
	// set ss's writer to that buffer.
	if maxBufSize > 0 {
		ss.bw = newBufferWriter(subBufMinShrinkSize, maxBufSize)
		ss.writer = ss.bw.createNewWriter(ss.file.handle)
	}
	if doRecover {
		if err := ss.recoverSubscriptions(); err != nil {
			fs.fm.unlockFile(ss.file)
			ss.Close()
			return nil, fmt.Errorf("unable to recover subscription store for [%s]: %v", channel, err)
		}
	}
	// Do not attempt to shrink unless the option is greater than the
	// minimum shrinkable size.
	if maxBufSize > subBufMinShrinkSize {
		// Use lock to avoid RACE report between setting shrinkTimer and
		// execution of the callback itself.
		ss.Lock()
		ss.allDone.Add(1)
		ss.shrinkTimer = time.AfterFunc(bufShrinkInterval, func() {
			ss.shrinkBuffer(true)
		})
		ss.Unlock()
	}
	if doRecover {
		fs.fm.closeLockedFile(ss.file)
	} else {
		fs.fm.unlockFile(ss.file)
	}
	return ss, nil
}
144693
func NewBlockStore(db dbm.DB) *BlockStore {
	bsjson := LoadBlockStoreStateJSON(db)
	return &BlockStore{
		height: bsjson.Height,
		db:     db,
	}
}
527835
func newFsBlockStore(id string, conf *Conf, indexConfig *blkstorage.IndexConfig,
	dbHandle *leveldbhelper.DBHandle) *fsBlockStore {
	return &fsBlockStore{id, conf, newBlockfileMgr(id, conf, indexConfig, dbHandle)}
}
933067
func NewUnboundedBuffer(mem, file int64) Buffer {
	return NewMulti(New(mem), NewPartition(NewFilePool(file, os.TempDir())))
}
583657
func NewBufferPool(size int, mem int) (bp *BufferPool) {
	return &BufferPool{
		c:     make(chan *bytes.Buffer, size),
		alloc: mem,
	}
}
618747
func NewBuffer(prompt string, out *os.File, echo bool) *Buffer {
	return &Buffer{
		Out:    out,
		Prompt: prompt,
		Echo:   echo,
	}
}
425074
func (lib *Lib) MakeBufferBytes(data []byte) (*Buffer, error) {
	if len(data) == 0 {
		return lib.GSS_C_NO_BUFFER, nil
	}

	// have to allocate the memory in C land and copy
	b, err := lib.MakeBuffer(allocMalloc)
	if err != nil {
		return nil, err
	}

	l := C.size_t(len(data))
	c := C.malloc(l)
	if b == nil {
		return nil, ErrMallocFailed
	}
	C.memmove(c, (unsafe.Pointer)(&data[0]), l)

	b.C_gss_buffer_t.length = l
	b.C_gss_buffer_t.value = c
	b.alloc = allocMalloc

	return b, nil
}
224156
func NewImageStore(fs StoreBackend, lss map[string]LayerGetReleaser) (Store, error) {
	is := &store{
		lss:       lss,
		images:    make(map[ID]*imageMeta),
		fs:        fs,
		digestSet: digestset.NewSet(),
	}

	// load all current images and retain layers
	if err := is.restore(); err != nil {
		return nil, err
	}

	return is, nil
}