//export blobChunkCb
182431
func blobChunkCb(buffer *C.char, maxLen C.size_t, handle unsafe.Pointer) int {
	payload := pointerHandles.Get(handle)
	data, ok := payload.(*BlobCallbackData)
	if !ok {
		panic("could not retrieve blob callback data")
	}

	goBuf, err := data.Callback(int(maxLen))
	if err == io.EOF {
		return 0
	} else if err != nil {
		data.Error = err
		return -1
	}
	C.memcpy(unsafe.Pointer(buffer), unsafe.Pointer(&goBuf[0]), C.size_t(len(goBuf)))
	return len(goBuf)
}
99380
func (c *Client) RemoveBlobs(ctx context.Context, blobs []blob.Ref) error {
	if c.sto != nil {
		return c.sto.RemoveBlobs(ctx, blobs)
	}
	pfx, err := c.prefix()
	if err != nil {
		return err
	}
	url_ := fmt.Sprintf("%s/camli/remove", pfx)
	params := make(url.Values)             // "blobN" -> BlobRefStr
	needsDelete := make(map[blob.Ref]bool) // BlobRefStr -> true
	for n, b := range blobs {
		if !b.Valid() {
			return errors.New("Cannot delete invalid blobref")
		}
		key := fmt.Sprintf("blob%v", n+1)
		params.Add(key, b.String())
		needsDelete[b] = true
	}

	req, err := http.NewRequest("POST", url_, strings.NewReader(params.Encode()))
	if err != nil {
		return fmt.Errorf("Error creating RemoveBlobs POST request: %v", err)
	}
	req = req.WithContext(ctx)
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	c.authMode.AddAuthHeader(req)
	resp, err := c.httpClient.Do(req)
	if err != nil {
		resp.Body.Close()
		return fmt.Errorf("Got status code %d from blobserver for remove %s", resp.StatusCode, params.Encode())
	}
	var remResp handlers.RemoveResponse
	decodeErr := httputil.DecodeJSON(resp, &remResp)
	if resp.StatusCode != 200 {
		resp.Body.Close()
		if decodeErr == nil {
			return fmt.Errorf("invalid http response %d in remove response: %v", resp.StatusCode, remResp.Error)
		} else {
			return fmt.Errorf("invalid http response %d in remove response", resp.StatusCode)
		}
	}
	if decodeErr != nil {
		return fmt.Errorf("failed to parse remove response: %v", err)
	}
	for _, br := range remResp.Removed {
		delete(needsDelete, br)
	}
	if len(needsDelete) > 0 {
		return fmt.Errorf("failed to remove blobs %s", strings.Join(stringKeys(needsDelete), ", "))
	}
	return nil
}
334741
func (bk *Backend) Export() ([]backend.Item, error) {
	var out []backend.Item

	// Get a list of all buckets in the backend.
	files, err := ioutil.ReadDir(path.Join(bk.rootDir))
	if err != nil {
		return nil, trace.ConvertSystemError(err)
	}

	// Loop over all buckets in the backend.
	for _, fi := range files {
		// skip sqlite database file - (in general sense,
		// dir backend lacked ability to skip files that
		// are present in the directory, so this is a necessary
		// evil that is going away with dir backend)
		if filepath.Base(fi.Name()) == "sqlite.db" {
			continue
		}
		pathToBucket := bk.pathToBucket(fi.Name())
		bucketParts, err := decodeBucket(filepath.Base(fi.Name()))
		if err != nil {
			return nil, trace.Wrap(err)
		}

		// Open the bucket to work on the items.
		b, err := bk.openBucket(pathToBucket, os.O_RDWR)
		if err != nil {
			return nil, trace.Wrap(err)
		}
		defer b.Close()

		// Loop over all keys, flatten them, and return key and value to caller.
		for k, v := range b.items {
			// If the bucket item is expired, update the bucket, and don't include
			// it in the output.
			if bk.isExpired(v) {
				b.deleteItem(k)
				continue
			}

			flatKey := make([]string, len(bucketParts))
			copy(flatKey, bucketParts)
			flatKey = append(flatKey, k)
			out = append(out, backend.Item{
				Key:     backend.Key(flatKey...),
				Value:   v.Value,
				Expires: v.ExpiryTime,
			})

		}
	}

	// Sort items and remove any duplicates.
	sort.Slice(out, func(i, j int) bool {
		return bytes.Compare(out[i].Key, out[j].Key) < 0
	})
	out = removeBackendDuplicates(out)

	return out, nil
}
591798
func ExportPreimages(db ethdb.Database, fn string) error {
	log.Info("Exporting preimages", "file", fn)

	// Open the file handle and potentially wrap with a gzip stream
	fh, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
	if err != nil {
		return err
	}
	defer fh.Close()

	var writer io.Writer = fh
	if strings.HasSuffix(fn, ".gz") {
		writer = gzip.NewWriter(writer)
		defer writer.(*gzip.Writer).Close()
	}
	// Iterate over the preimages and export them
	it := db.NewIteratorWithPrefix([]byte("secure-key-"))
	for it.Next() {
		if err := rlp.Encode(writer, it.Value()); err != nil {
			return err
		}
	}
	log.Info("Exported preimages", "file", fn)
	return nil
}
1233687
func (s *Storage) BlobContents(br blob.Ref) (contents string, ok bool) {
	s.mu.RLock()
	defer s.mu.RUnlock()
	b, ok := s.m[br]
	if !ok {
		return
	}
	return string(b), true
}
1048984
func (x *XC) ExportPublicKey(ctx context.Context, id string) ([]byte, error) {
	if x.pubring.Contains(id) {
		return x.pubring.Export(id)
	}
	if x.secring.Contains(id) {
		return x.secring.Export(id, false)
	}
	return nil, fmt.Errorf("key not found")
}
1278965
func BlobpackedRecoveryValue() int {
	recovery, err := metadata.InstanceAttributeValue("camlistore-recovery")
	if err != nil {
		if _, ok := err.(metadata.NotDefinedError); !ok {
			log.Printf("error getting camlistore-recovery: %v", err)
		}
		return 0
	}
	if recovery == "" {
		return 0
	}
	mode, err := strconv.Atoi(recovery)
	if err != nil {
		log.Printf("invalid int value for \"camlistore-recovery\": %v", err)
	}
	return mode
}
564845
func GetBlob(s storer.EncodedObjectStorer, h plumbing.Hash) (*Blob, error) {
	o, err := s.EncodedObject(plumbing.BlobObject, h)
	if err != nil {
		return nil, err
	}

	return DecodeBlob(o)
}
467871
func (c container) Blob(name string) Blob {
	return blob{c.Container.GetBlobReference(name)}
}
987831
func (c *xContext) XMLBlob(b []byte, codes ...int) (err error) {
	c.response.Header().Set(HeaderContentType, MIMEApplicationXMLCharsetUTF8)
	b = []byte(xml.Header + string(b))
	err = c.Blob(b, codes...)
	return
}
1222146
func (s *LDBStore) Export(out io.Writer) (int64, error) {
	tw := tar.NewWriter(out)
	defer tw.Close()

	it := s.db.NewIterator()
	defer it.Release()
	var count int64
	for ok := it.Seek([]byte{keyIndex}); ok; ok = it.Next() {
		key := it.Key()
		if (key == nil) || (key[0] != keyIndex) {
			break
		}

		var index dpaDBIndex

		hash := key[1:]
		decodeIndex(it.Value(), &index)
		po := s.po(hash)
		datakey := getDataKey(index.Idx, po)
		log.Trace("store.export", "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po)
		data, err := s.db.Get(datakey)
		if err != nil {
			log.Warn(fmt.Sprintf("Chunk %x found but could not be accessed: %v", key, err))
			continue
		}

		hdr := &tar.Header{
			Name: hex.EncodeToString(hash),
			Mode: 0644,
			Size: int64(len(data)),
		}
		if err := tw.WriteHeader(hdr); err != nil {
			return count, err
		}
		if _, err := tw.Write(data); err != nil {
			return count, err
		}
		count++
	}

	return count, nil
}
1080334
func (c *Certificate) Export() ([]byte, error) {
	pemBlock := &pem.Block{
		Type:    certificatePEMBlockType,
		Headers: nil,
		Bytes:   c.derBytes,
	}

	buf := new(bytes.Buffer)
	if err := pem.Encode(buf, pemBlock); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
1345013
func (_class BlobClass) GetPublic(sessionID SessionRef, self BlobRef) (_retval bool, _err error) {
	_method := "blob.get_public"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertBlobRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertBoolToGo(_method + " -> ", _result.Value)
	return
}
506215
func (c container) Blobs() ([]Blob, error) {
	//TODO(axw) handle pagination.
	resp, err := c.Container.ListBlobs(storage.ListBlobsParameters{})
	if err != nil {
		return nil, errors.Trace(err)
	}
	blobs := make([]Blob, len(resp.Blobs))
	for i := range blobs {
		blobs[i] = blob{&resp.Blobs[i]}
	}
	return blobs, nil
}
800385
func (h *Histogram) Export() *Snapshot {
	return &Snapshot{
		LowestTrackableValue:  h.lowestTrackableValue,
		HighestTrackableValue: h.highestTrackableValue,
		SignificantFigures:    h.significantFigures,
		Counts:                append([]int64(nil), h.counts...), // copy
	}
}
28157
func (g *Geometry) WKB() ([]byte, error) {
	encoder := newWkbEncoder()
	return encoder.encode(g)
}
50119
func (v *BtrfsVolume) Export(label, parent string, writer io.Writer, excludes []string) error {
	if len(excludes) > 0 {
		glog.Warning("btrfs backups do not support excluding directories")
	}
	if label = strings.TrimSpace(label); label == "" {
		glog.Errorf("%s: label cannot be empty", volume.DriverTypeBtrFS)
		return ErrBtrfsInvalidLabel
	} else if exists, err := v.snapshotExists(label); err != nil {
		return err
	} else if !exists {
		return volume.ErrSnapshotDoesNotExist
	}
	// TODO: add to tarfile and include metadata
	if err := runBtrfsSend(writer, v.sudoer, parent, v.snapshotPath(label)); err != nil {
		glog.Errorf("Could not export snapshot %s: %s", label, err)
		return err
	}
	return nil
}