// Export used export data from a exchange Resource
//     product.Export(csv.New("products.csv"), context)
337516
func (res *Resource) Export(container Container, context *qor.Context, callbacks ...func(Progress) error) error {
	var (
		total   uint
		results = res.NewSlice()
		err     = context.GetDB().Find(results).Count(&total).Error
	)

	if err == nil {
		reflectValue := reflect.Indirect(reflect.ValueOf(results))

		writer, err := container.NewWriter(res, context)

		if err == nil {
			writer.WriteHeader()

			for i := 0; i < reflectValue.Len(); i++ {
				var result = reflectValue.Index(i).Interface()
				var metaValues *resource.MetaValues
				if metaValues, err = writer.WriteRow(result); err != nil {
					return err
				}

				var progress = Progress{
					Current: uint(i + 1),
					Total:   total,
					Value:   result,
				}

				for _, metaValue := range metaValues.Values {
					progress.Cells = append(progress.Cells, Cell{
						Header: metaValue.Name,
						Value:  metaValue.Value,
					})
				}

				for _, callback := range callbacks {
					if err := callback(progress); err != nil {
						return err
					}
				}
			}
			err = writer.Flush()
		}

		return err
	}

	return err
}
1310733
func (sink *RiemannSink) ExportData(dataBatch *core.DataBatch) {
	sink.Lock()
	defer sink.Unlock()

	if sink.client == nil {
		// the client could be nil here, so we reconnect
		client, err := riemannCommon.GetRiemannClient(sink.config)
		if err != nil {
			glog.Warningf("Riemann sink not connected: %v", err)
			return
		}
		sink.client = client
	}

	var events []riemanngo.Event

	for _, metricSet := range dataBatch.MetricSets {
		host := metricSet.Labels[core.LabelHostname.Key]
		for metricName, metricValue := range metricSet.MetricValues {
			if value := metricValue.GetValue(); value != nil {
				timestamp := dataBatch.Timestamp.Unix()
				// creates an event and add it to dataEvent
				events = appendEvent(events, sink, host, metricName, value, metricSet.Labels, timestamp)
			}
		}
		for _, metric := range metricSet.LabeledMetrics {
			if value := metric.GetValue(); value != nil {
				labels := make(map[string]string)
				for k, v := range metricSet.Labels {
					labels[k] = v
				}
				for k, v := range metric.Labels {
					labels[k] = v
				}
				timestamp := dataBatch.Timestamp.Unix()
				// creates an event and add it to dataEvent
				events = appendEvent(events, sink, host, metric.Name, value, labels, timestamp)
			}
		}
	}
	// Send events to Riemann if events is not empty
	if len(events) > 0 {
		err := riemannCommon.SendData(sink.client, events)
		if err != nil {
			glog.Warningf("Error sending events to Riemann: %v", err)
			// client will reconnect later
			sink.client = nil
		}
	}
}
246368
func export(w io.Writer, un unstructured.Unstructured) {
	name := un.GetName()
	finalizers := un.GetFinalizers()
	apiVersion := un.GetAPIVersion()
	kind := un.GetKind()
	labels := un.GetLabels()
	annotations := un.GetAnnotations()
	unstructured.RemoveNestedField(un.Object, "metadata")
	un.SetName(name)
	un.SetFinalizers(finalizers)
	un.SetAPIVersion(apiVersion)
	un.SetKind(kind)
	un.SetLabels(labels)
	un.SetAnnotations(annotations)
	data, err := yaml.Marshal(un.Object)
	errors.CheckError(err)
	_, err = w.Write(data)
	errors.CheckError(err)
	_, err = w.Write([]byte(yamlSeparator))
	errors.CheckError(err)
}
1099263
func (dfs *DistributedFilesystem) export(path string) error {
	if err := dfs.net.AddVolume(path); err != nil {
		glog.Errorf("Error notifying storage of new volume %s: %s", path, err)
		return err
	} else if err := dfs.net.Sync(); err != nil {
		glog.Errorf("Error syncing storage for volume %s: %s", path, err)
		return err
	}
	return nil
}
1282129
func (bc *BlockChain) Export(w io.Writer) error {
	return bc.ExportN(w, uint64(0), bc.CurrentBlock().NumberU64())
}
965490
func (c *Client) Export(ctx context.Context, name string) (int, error) {

	ok, id, err := c.IsExported(ctx, name)
	if err != nil {
		return 0, err
	}
	if ok {
		return id, nil
	}

	paths := []string{c.API.VolumePath(name)}

	return api.ExportCreate(
		ctx, c.API,
		&api.Export{Paths: &paths})
}
549752
func (mg *MailgunImpl) GetExport(ctx context.Context, id string) (Export, error) {
	r := newHTTPRequest(generatePublicApiUrl(mg, exportsEndpoint) + "/" + id)
	r.setClient(mg.Client())
	r.setBasicAuth(basicAuthUser, mg.APIKey())
	var resp Export
	err := getResponseFromJSON(ctx, r, &resp)
	return resp, err
}
1034778
func (i item) export(f gregor.ObjFactory) (gregor.Item, error) {
	md := i.item.Metadata()
	return f.MakeItem(md.UID(), md.MsgID(), md.DeviceID(), i.ctime, i.item.Category(), i.dtime, i.item.Body())
}
1009635
func (ks *KeyStore) Export(a accounts.Account, passphrase, newPassphrase string) (keyJSON []byte, err error) {
	_, key, err := ks.getDecryptedKey(a, passphrase)
	if err != nil {
		return nil, err
	}
	var N, P int
	if store, ok := ks.storage.(*keyStorePassphrase); ok {
		N, P = store.scryptN, store.scryptP
	} else {
		N, P = StandardScryptN, StandardScryptP
	}
	return EncryptKey(key, newPassphrase, N, P)
}
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
}
184232
func Export(
	ctx context.Context,
	client api.Client,
	path string) (err error) {
	// PAPI call: POST https://1.2.3.4:8080/platform/1/protocols/nfs/exports/
	//            Content-Type: application/json
	//            {paths: ["/path/to/volume"]}

	if path == "" {
		return errors.New("no path set")
	}

	var data = &ExportPathList{Paths: []string{path}}
	data.MapAll.User = client.User()
	if group := client.Group(); group != "" {
		data.MapAll.Groups = append(data.MapAll.Groups, group)
	}
	var resp *postIsiExportResp

	err = client.Post(ctx, exportsPath, "", nil, nil, data, &resp)

	if err != nil {
		return err
	}

	return nil
}
1171351
func (w *Word) Export(precision int) string {
	x := strconv.FormatFloat(w.Command, 'f', precision, 64)

	// Hacky way to remove silly zeroes
	if strings.IndexRune(x, '.') != -1 {
		for x[len(x)-1] == '0' {
			x = x[:len(x)-1]
		}
		if x[len(x)-1] == '.' {
			x = x[:len(x)-1]
		}
	}

	return string(w.Address) + x
}
688711
func ExportsList(
	ctx context.Context,
	client api.Client) ([]*Export, error) {

	var resp ExportList

	if err := client.Get(
		ctx,
		exportsPath,
		"",
		nil,
		nil,
		&resp); err != nil {

		return nil, err
	}

	return resp, nil
}
1178067
func (p *RPCClientV7) Export(ctx context.Context) ([]byte, error) {
	var resp ExportResponse
	err := p.client.Call("RPCServer.Export", struct{}{}, &resp)
	if err != nil {
		if _, ok := err.(rpc.ServerError); !ok && err != nil {
			return resp.Result, remote.FatalError{err}
		}
		return resp.Result, err
	}
	err = resp.ApplicationError
	return resp.Result, err
}
625545
func (d *Driver) exportLayer(id string, parentLayerPaths []string) (io.ReadCloser, error) {
	archive, w := io.Pipe()
	go func() {
		err := winio.RunWithPrivilege(winio.SeBackupPrivilege, func() error {
			r, err := hcsshim.NewLayerReader(d.info, id, parentLayerPaths)
			if err != nil {
				return err
			}

			err = writeTarFromLayer(r, w)
			cerr := r.Close()
			if err == nil {
				err = cerr
			}
			return err
		})
		w.CloseWithError(err)
	}()

	return archive, nil
}
772986
func Export(inst *Instagram, writer io.Writer) error {
	url, err := neturl.Parse(goInstaAPIUrl)
	if err != nil {
		return err
	}

	config := ConfigFile{
		ID:        inst.Account.ID,
		User:      inst.user,
		DeviceID:  inst.dID,
		UUID:      inst.uuid,
		RankToken: inst.rankToken,
		Token:     inst.token,
		PhoneID:   inst.pid,
		Cookies:   inst.c.Jar.Cookies(url),
	}
	bytes, err := json.Marshal(config)
	if err != nil {
		return err
	}
	_, err = writer.Write(bytes)
	return err
}
435323
func (v *DeviceMapperVolume) Export(label, parent string, writer io.Writer, excludes []string) error {
	glog.V(2).Infof("Export() (%s) START", v.name)
	defer glog.V(2).Infof("Export() (%s) END", v.name)
	if !v.snapshotExists(label) {
		return volume.ErrSnapshotDoesNotExist
	}
	label = v.rawSnapshotLabel(label)
	mountpoint, err := ioutil.TempDir("", "serviced-export-volume-")
	if err != nil {
		return err
	}
	defer os.RemoveAll(mountpoint)
	deviceHash, err := v.Metadata.LookupSnapshotDevice(label)
	if err != nil {
		return err
	}
	glog.V(2).Infof("Mounting temporary export device %s", deviceHash)
	if err := v.driver.DeviceSet.MountDevice(deviceHash, mountpoint, label); err != nil {
		return err
	}
	defer func(d *DeviceMapperDriver, deviceHash, mountpoint string) {
		// We use the provided UnmountDevice func here, rather than our own
		// unmount(), because we DO care about Docker's internal bookkeeping
		// here. Without this, DeviceSet.DeleteDevice will fail.
		if err := d.DeviceSet.UnmountDevice(deviceHash, mountpoint); err != nil {
			glog.V(2).Infof("Error unmounting %s (device: %s): %s", mountpoint, deviceHash, err)
		}
		d.DeviceSet.Lock()
		if err := d.DeactivateDevice(deviceHash); err != nil {
			glog.V(2).Infof("Error deactivating device %s: %s", deviceHash, err)
		}
		d.DeviceSet.Unlock()
	}(v.driver, deviceHash, mountpoint)

	tarOut := tar.NewWriter(writer)

	// Set the driver type
	drivertype := []byte(v.Driver().DriverType())
	header := &tar.Header{Name: fmt.Sprintf("%s-driver", label), Size: int64(len(drivertype))}
	if err := tarOut.WriteHeader(header); err != nil {
		glog.Errorf("Could not export driver type header for snapshot %s: %s", label, err)
		return err
	}
	if _, err := tarOut.Write(drivertype); err != nil {
		glog.Errorf("Could not export driver type for snapshot %s: %s", label, err)
		return err
	}

	// Set the device metadata
	size, err := v.SizeOf()
	if err != nil {
		glog.Errorf("Could not get the size of the device for snapshot %s: %s", label, err)
		return err
	}
	volInfo, err := json.Marshal(volumeInfo{Size: size})
	if err != nil {
		glog.Errorf("Could not marshal device info for snapshot %s: %s", label, err)
		return err
	}
	header = &tar.Header{Name: fmt.Sprintf("%s-device", label), Size: int64(len(volInfo))}
	if err := tarOut.WriteHeader(header); err != nil {
		glog.Errorf("Could not export device info header for snapshot %s: %s", label, err)
		return err
	}
	if _, err := tarOut.Write(volInfo); err != nil {
		glog.Errorf("Could not export device info for snapshot %s: %s", label, err)
		return err
	}

	// Write metadata
	mdpath := filepath.Join(v.driver.MetadataDir(), label)

	if err := exportDirectoryAsTar(mdpath, fmt.Sprintf("%s-metadata", label), tarOut, []string{}); err != nil {
		return err
	}
	if err := exportDirectoryAsTar(mountpoint, fmt.Sprintf("%s-volume", label), tarOut, excludes); err != nil {
		return err
	}

	return tarOut.Close()
}