// ImportByReader imports the the translations found within the contents read from the supplied reader.
//
// NOTE: generally used when assets have been embedded into the binary and are already in memory.
974694
func (t *UniversalTranslator) ImportByReader(format ImportExportFormat, reader io.Reader) error {

	b, err := ioutil.ReadAll(reader)
	if err != nil {
		return err
	}

	var trans []translation

	switch format {
	case FormatJSON:
		err = json.Unmarshal(b, &trans)
	}

	if err != nil {
		return err
	}

	for _, tl := range trans {

		locale, found := t.FindTranslator(tl.Locale)
		if !found {
			return &ErrMissingLocale{locale: tl.Locale}
		}

		pr := stringToPR(tl.PluralRule)

		if pr == locales.PluralRuleUnknown {

			err = locale.Add(tl.Key, tl.Translation, tl.OverrideExisting)
			if err != nil {
				return err
			}

			continue
		}

		switch tl.PluralType {
		case cardinalType:
			err = locale.AddCardinal(tl.Key, tl.Translation, pr, tl.OverrideExisting)
		case ordinalType:
			err = locale.AddOrdinal(tl.Key, tl.Translation, pr, tl.OverrideExisting)
		case rangeType:
			err = locale.AddRange(tl.Key, tl.Translation, pr, tl.OverrideExisting)
		default:
			return &ErrBadPluralDefinition{tl: tl}
		}

		if err != nil {
			return err
		}
	}

	return nil
}
1103060
func SliceFromReader(r io.Reader) (Slice, error) {
	if r, ok := r.(*bufio.Reader); ok {
		// Buffered reader can use faster path.
		return sliceFromBufReader(r)
	}
	hdr := make(Slice, 1, maxByteSizeBytes)
	// Read first byte
	if err := readBytes(hdr, r); err != nil {
		if Cause(err) == io.EOF {
			// Empty slice
			return nil, nil
		}
		return nil, WithStack(err)
	}
	// Lookup first size
	// check if the type has a fixed length first
	l := fixedTypeLengths[hdr[0]]
	if l != 0 {
		// Found fixed length, read it (minus byte already read)
		s := make(Slice, l)
		s[0] = hdr[0]
		if err := readBytes(s[1:], r); err != nil {
			return nil, WithStack(err)
		}
		return s, nil
	}

	readRemaining := func(prefix Slice, l ValueLength) (Slice, error) {
		s := make(Slice, l)
		copy(s, prefix)
		if err := readBytes(s[len(prefix):], r); err != nil {
			return nil, WithStack(err)
		}
		return s, nil
	}

	// types with dynamic lengths need special treatment:
	h := hdr[0]
	switch hdr.Type() {
	case Array, Object:
		if h == 0x13 || h == 0x14 {
			// compact Array or Object
			l, bytes, err := readVariableValueLengthFromReader(r, false)
			if err != nil {
				return nil, WithStack(err)
			}
			return readRemaining(append(hdr, bytes...), l)
		}

		vpackAssert(h > 0x00 && h <= 0x0e)
		l, bytes, err := readIntegerNonEmptyFromReader(r, widthMap[h])
		if err != nil {
			return nil, WithStack(err)
		}
		return readRemaining(append(hdr, bytes...), ValueLength(l))

	case String:
		vpackAssert(h == 0xbf)

		// long UTF-8 String
		l, bytes, err := readIntegerFixedFromReader(r, 8)
		if err != nil {
			return nil, WithStack(err)
		}
		return readRemaining(append(hdr, bytes...), ValueLength(l+1+8))

	case Binary:
		vpackAssert(h >= 0xc0 && h <= 0xc7)
		x, bytes, err := readIntegerNonEmptyFromReader(r, uint(h)-0xbf)
		if err != nil {
			return nil, WithStack(err)
		}
		l := ValueLength(1 + ValueLength(h) - 0xbf + ValueLength(x))
		return readRemaining(append(hdr, bytes...), l)

	case BCD:
		if h <= 0xcf {
			// positive BCD
			vpackAssert(h >= 0xc8 && h < 0xcf)
			x, bytes, err := readIntegerNonEmptyFromReader(r, uint(h)-0xc7)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(1 + ValueLength(h) - 0xc7 + ValueLength(x))
			return readRemaining(append(hdr, bytes...), l)
		}

		// negative BCD
		vpackAssert(h >= 0xd0 && h < 0xd7)
		x, bytes, err := readIntegerNonEmptyFromReader(r, uint(h)-0xcf)
		if err != nil {
			return nil, WithStack(err)
		}
		l := ValueLength(1 + ValueLength(h) - 0xcf + ValueLength(x))
		return readRemaining(append(hdr, bytes...), l)

	case Custom:
		vpackAssert(h >= 0xf4)
		switch h {
		case 0xf4, 0xf5, 0xf6:
			x, bytes, err := readIntegerFixedFromReader(r, 1)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(2 + x)
			return readRemaining(append(hdr, bytes...), l)
		case 0xf7, 0xf8, 0xf9:
			x, bytes, err := readIntegerFixedFromReader(r, 2)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(3 + x)
			return readRemaining(append(hdr, bytes...), l)
		case 0xfa, 0xfb, 0xfc:
			x, bytes, err := readIntegerFixedFromReader(r, 4)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(5 + x)
			return readRemaining(append(hdr, bytes...), l)
		case 0xfd, 0xfe, 0xff:
			x, bytes, err := readIntegerFixedFromReader(r, 8)
			if err != nil {
				return nil, WithStack(err)
			}
			l := ValueLength(9 + x)
			return readRemaining(append(hdr, bytes...), l)
		}
	}

	return nil, WithStack(InternalError)
}
74694
func (r *importReader) readByte() byte {
	c, err := r.b.ReadByte()
	if err == nil {
		r.buf = append(r.buf, c)
		if c == 0 {
			err = errNUL
		}
	}
	if err != nil {
		if err == io.EOF {
			r.eof = true
		} else if r.err == nil {
			r.err = err
		}
		c = 0
	}
	return c
}
174695
func ImportKeys(r io.Reader) ([]*Account, error) {
	res, ok := readAccounts(bufio.NewReader(r))
	if !ok {
		return nil, newOtrError("couldn't import data into private key")
	}
	return res, nil
}
335950
func FromBinaryReader(r io.Reader) *Graph {
	p := newBinParser(r)
	return p.parse()
}
786042
func LoadReader(r io.Reader) error {
	env, err := Read(r)
	if err != nil {
		return err
	}
	LoadMap(env, false)
	return nil
}
703496
func (rs *Ruleset) LoadReader(r io.Reader) error {
	m := map[string]string{}
	err := json.NewDecoder(r).Decode(&m)
	if err != nil {
		return fmt.Errorf("could not decode inflection JSON from reader: %s", err)
	}
	for s, p := range m {
		defaultRuleset.AddIrregular(s, p)
	}
	return nil
}
239745
func (impl *repoImpl) packageReader(c context.Context, ref *api.ObjectRef) (*processing.PackageReader, error) {
	// Get slow Google Storage based ReaderAt.
	rawReader, err := impl.cas.GetReader(c, ref)
	switch code := grpc.Code(err); {
	case code == codes.NotFound:
		return nil, errors.Annotate(err, "package instance is not in the storage").Err()
	case code != codes.OK:
		return nil, errors.Annotate(err, "failed to open the object for reading").Tag(transient.Tag).Err()
	}

	// Read in 512 Kb chunks, keep 2 of them buffered.
	pkg, err := processing.NewPackageReader(
		iotools.NewBufferingReaderAt(rawReader, 512*1024, 2),
		rawReader.Size())
	if err != nil {
		return nil, errors.Annotate(err, "error when opening the package").Err()
	}
	return pkg, nil
}
408873
func (cache *ImportCache) ImportString(importedFrom, importedPath string, i *interpreter, trace TraceElement) (*valueString, error) {
	data, _, err := cache.importData(importedFrom, importedPath)
	if err != nil {
		return nil, i.Error(err.Error(), trace)
	}
	return makeValueString(data.String()), nil
}
390980
func (r *importReader) readKeyword(kw string) {
	r.peekByte(true)
	for i := 0; i < len(kw); i++ {
		if r.nextByte(false) != kw[i] {
			r.syntaxError()
			return
		}
	}
	if isIdent(r.peekByte(false)) {
		r.syntaxError()
	}
}
1191092
func (bi *blockImporter) Import() chan *importResults {
	// Start up the read and process handling goroutines.  This setup allows
	// blocks to be read from disk in parallel while being processed.
	bi.wg.Add(2)
	go bi.readHandler()
	go bi.processHandler()

	// Wait for the import to finish in a separate goroutine and signal
	// the status handler when done.
	go func() {
		bi.wg.Wait()
		bi.doneChan <- true
	}()

	// Start the status handler and return the result channel that it will
	// send the results on when the import is done.
	resultChan := make(chan *importResults)
	go bi.statusHandler(resultChan)
	return resultChan
}
784216
func (a *API) ImportPath() string {
	return path.Join(a.BaseImportPath, a.PackageName())
}
813529
func (engine *Engine) Import(r io.Reader) ([]sql.Result, error) {
	var results []sql.Result
	var lastError error
	scanner := bufio.NewScanner(r)

	semiColSpliter := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		if atEOF && len(data) == 0 {
			return 0, nil, nil
		}
		if i := bytes.IndexByte(data, ';'); i >= 0 {
			return i + 1, data[0:i], nil
		}
		// If we're at EOF, we have a final, non-terminated line. Return it.
		if atEOF {
			return len(data), data, nil
		}
		// Request more data.
		return 0, nil, nil
	}

	scanner.Split(semiColSpliter)

	for scanner.Scan() {
		query := strings.Trim(scanner.Text(), " \t\n\r")
		if len(query) > 0 {
			engine.logSQL(query)
			result, err := engine.DB().Exec(query)
			results = append(results, result)
			if err != nil {
				return nil, err
			}
		}
	}

	return results, lastError
}
1029976
func (v *NFSVolume) Import(label string, reader io.Reader) error {
	return ErrNotSupported
}
1357803
func NewReader(r io.Reader) (*Reader, error) {
	zlib, err := zlib.NewReader(r)
	if err != nil {
		return nil, packfile.ErrZLib.AddDetails(err.Error())
	}

	return &Reader{
		zlib: zlib,
	}, nil
}
541032
func (v *RsyncVolume) Import(label string, reader io.Reader) error {
	v.Lock()
	defer v.Unlock()
	label = v.rawSnapshotLabel(label)
	if exists, err := volume.IsDir(v.snapshotPath(label)); err != nil {
		return err
	} else if exists {
		return volume.ErrSnapshotExists
	}
	driverfile := fmt.Sprintf("%s-driver", label)
	volumedir := fmt.Sprintf("%s-volume", label)
	metadatadir := fmt.Sprintf("%s-metadata", label)
	var drivertype string
	tarfile := tar.NewReader(reader)
	for {
		header, err := tarfile.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			glog.Errorf("Could not import archive: %s", err)
			return err
		}
		if header.Name == driverfile {
			buf := bytes.NewBufferString("")
			if _, err := buf.ReadFrom(tarfile); err != nil {
				return err
			}
			drivertype = buf.String()
		} else if strings.HasPrefix(header.Name, volumedir) {
			header.Name = strings.Replace(header.Name, volumedir, label, 1)
			if err := volume.ImportArchiveHeader(header, tarfile, v.driver.Root()); err != nil {
				return err
			}
		} else if strings.HasPrefix(header.Name, metadatadir) {
			header.Name = strings.Replace(header.Name, metadatadir, label, 1)
			if err := volume.ImportArchiveHeader(header, tarfile, v.driver.MetadataDir()); err != nil {
				return err
			}
		}
	}
	if drivertype == "" {
		return errors.New("incompatible snapshot")
	}
	return nil
}
488147
func (g Generator) Imports() map[string]string {
	imports := imports.New(g.Package())
	for _, m := range g.Methods() {
		s := m.signature()
		imports.AddImportsFrom(s.Params())
		imports.AddImportsFrom(s.Results())
	}
	return imports.Imports()
}