Store Avro values into an Avro-container blob.

The returned stream will emit a single value, the blob, when ended.
960472
function createBlobEncoder(schema, opts) {
  var encoder = new containers.streams.BlockEncoder(schema, opts);
  var builder = new BlobWriter();
  encoder.pipe(builder);
  return new stream.Duplex({
    objectMode: true,
    read: function () {
      // Not the fastest implementation, but it will only be called at most
      // once (since the builder only ever emits a single value) so it'll do.
      // It's also likely impractical to create very large blobs.
      var val = builder.read();
      if (val) {
        done(val);
      } else {
        builder.once('readable', done);
      }
      var self = this;
      function done(val) {
        self.push(val || builder.read());
        self.push(null);
      }
    },
    write: function (val, encoding, cb) {
      return encoder.write(val, encoding, cb);
    }
  }).on('finish', function () { encoder.end(); });
}
1354641
function(endTime) {
    const opcode = encoders.opcode('RESET_STREAM');

    const endTimeBuffer = new Float64Array(1);
    endTimeBuffer[0] = endTime;

    const payload = new Uint16Array(1 + 4);
    payload.set(opcode, 0);
    payload.set(new Uint16Array(endTimeBuffer.buffer), 1);

    return payload.buffer;
  }
1281074
def store(self, key, value):
        """"""
        # Prepend tweepy to our key,
        # this makes it easier to identify tweepy keys in our redis server
        key = self.pre_identifier + key
        # Get a pipe (to execute several redis commands in one step)
        pipe = self.client.pipeline()
        # Set our values in a redis hash (similar to python dict)
        pipe.set(key, pickle.dumps((time.time(), value)))
        # Set the expiration
        pipe.expire(key, self.timeout)
        # Add the key to a set containing all the keys
        pipe.sadd(self.keys_container, key)
        # Execute the instructions in the redis server
        pipe.execute()
832050
async def container_val(self, elem, container_type, params=None):
        
        if hasattr(container_type, 'boost_serialize'):
            raise ValueError('not supported')

        if self.writing:
            elem_type = params[0] if params else None
            if elem_type is None:
                elem_type = container_type.ELEM_TYPE

            await self.dump_field(elem, elem_type, params[1:] if params else None)

        else:
            raise ValueError('Not supported')
183766
def push(self, value):
        

        stream = DataStream.FromEncoded(value.stream)

        if stream.stream_type == DataStream.OutputType:
            if len(self.streaming_data) == self.streaming_length:
                raise StorageFullError('Streaming buffer full')

            self.streaming_data.append(value)
        else:
            if len(self.storage_data) == self.storage_length:
                raise StorageFullError('Storage buffer full')

            self.storage_data.append(value)
101369
def store_data_blob(self, hexdata, wifs, change_address=None,
                        txouts=None, fee=10000, lock_time=0,
                        dust_limit=common.DUST_LIMIT):
        """"""
        rawtx = self.create_tx(txouts=txouts, lock_time=lock_time)
        rawtx = self.add_data_blob(rawtx, hexdata, dust_limit=dust_limit)
        rawtx = self.add_inputs(rawtx, wifs, change_address=change_address,
                                fee=fee)
        return self.publish(rawtx)
1169623
def write
      begin
        buf = [ @flags, @length, @id, @crc].pack(FORMAT)
        crc = Zlib.crc32(buf, 0)
        @file.seek(@addr)
        @file.write(buf + [ crc ].pack('L'))
      rescue IOError => e
        PEROBS.log.fatal "Cannot write blob header into flat file DB: " +
          e.message
      end
    end
634582
def ToArray(value):
        
        ms = StreamManager.GetStream()
        writer = BinaryWriter(ms)

        value.Serialize(writer)

        retVal = ms.ToArray()
        StreamManager.ReleaseStream(ms)

        return retVal
442905
async def dump_container(obj, container, container_type, params=None, field_archiver=None):
    
    field_archiver = field_archiver if field_archiver else dump_field
    elem_type = params[0] if params else None
    if elem_type is None:
        elem_type = container_type.ELEM_TYPE

    obj = [] if obj is None else get_elem(obj)
    if container is None:
        return None
    for elem in container:
        fvalue = await field_archiver(None, elem, elem_type, params[1:] if params else None)
        obj.append(fvalue)
    return obj
898878
async def load_blob(reader, elem_type, params=None, elem=None):
    
    ivalue = elem_type.SIZE if elem_type.FIX_SIZE else await load_uvarint(reader)
    fvalue = bytearray(ivalue)
    await reader.areadinto(fvalue)

    if elem is None:
        return fvalue  # array by default

    elif isinstance(elem, BlobType):
        setattr(elem, elem_type.DATA_ATTR, fvalue)
        return elem

    else:
        elem.extend(fvalue)

    return elem
1046549
def attach(self, stdout=True, stderr=True, stream=True, logs=False):
        

        try:
            data = parse_stream(self.client.attach(self.id, stdout, stderr, stream, logs))
        except KeyboardInterrupt:
            logger.warning(
                "service container: {0} has been interrupted. "
                "The container will be stopped but will not be deleted.".format(self.name)
            )
            data = None
            self.stop()

        return data
708593
def extern_store_tuple(self, context_handle, vals_ptr, vals_len):
    """"""
    c = self._ffi.from_handle(context_handle)
    return c.to_value(tuple(c.from_value(val[0]) for val in self._ffi.unpack(vals_ptr, vals_len)))
832578
def save(self, io, little_endian=False):
        
        if little_endian:
            write = lambda fmt, *args: io.write(pack('<' + fmt, *args))
        else:
            write = lambda fmt, *args: io.write(pack('>' + fmt, *args))
        write.io = io

        self.write(write)
149332
def store(self, name, value, atype, new_name=None, multiplier=None, allowed_values=None):
        '''  '''
        if value is not None:
            _bad_type = (not isinstance(value, atype))
            if not _bad_type:
                # special case
                _bad_type = (isinstance(value, bool) and atype == int)

            if _bad_type:
                # could be a special value
                if allowed_values and value in allowed_values:
                    allowed_values = None
                else:
                    raise ValueError("%s should be value of type (%s)" % (name, atype.__name__))

            if allowed_values:
                if isinstance(value, str):
                    if value not in allowed_values:
                        raise ValueError("%s can be %s" % (name, allowed_values))
                elif isinstance(value, int):
                    if isinstance(allowed_values[0], int):
                        if value < allowed_values[0]:
                            raise ValueError("%s must be >= %d" % (name, allowed_values[0]))

            _val = value if not multiplier else (multiplier * value)
            _name = name if not new_name else new_name
            self._dict[_name] = _val
697334
def WriteBlobs(self, blob_id_data_map):
    """"""

    urns = {self._BlobUrn(blob_id): blob_id for blob_id in blob_id_data_map}

    mutation_pool = data_store.DB.GetMutationPool()

    existing = aff4.FACTORY.MultiOpen(
        urns, aff4_type=aff4.AFF4MemoryStreamBase, mode="r")

    for blob_urn, blob_id in iteritems(urns):
      if blob_urn in existing:
        logging.debug("Blob %s already stored.", blob_id)
        continue

      with aff4.FACTORY.Create(
          blob_urn,
          aff4.AFF4UnversionedMemoryStream,
          mode="w",
          mutation_pool=mutation_pool) as fd:
        content = blob_id_data_map[blob_id]
        fd.Write(content)

      logging.debug("Got blob %s (length %s)", blob_id.AsHexString(),
                    len(content))

    mutation_pool.Flush()
1370957
def storeFromWav(self, uploadCacheEntry, start, end):
        
        prefix = uploadCacheEntry['name'] + '_' + start + '_' + end
        match = next((x for x in self._cache.values() if x['type'] == 'wav' and x['name'].startswith(prefix)), None)
        if match is None:
            cached = [
                {
                    'name': prefix + '_' + n,
                    'analysis': n,
                    'start': start,
                    'end': end,
                    'type': 'wav',
                    'filename': uploadCacheEntry['name']
                } for n in ['spectrum', 'peakSpectrum']
            ]
            for cache in cached:
                self._cache[cache['name']] = cache
            self.writeCache()
            return True
        return False
1366789
def __store_service(self, key, service):
        
        self._future_value.setdefault(key, []).append(service)