Beispiel #1
0
 def testB64EncodedData(self):
   is_compressed = False
   handle = trace_data.TraceFileHandle(is_compressed)
   handle.Open()
   original_data = {"msg": "The answer is 42"}
   b64_data = base64.b64encode(json.dumps(original_data))
   handle.AppendTraceData(b64_data, b64=True)
   handle.Close()
   out_data = handle.AsTraceData()
   self.assertEqual(original_data, out_data)
Beispiel #2
0
 def Read(self, callback):
     # Do not allow the instance of this class to be reused, as
     # we only read data sequentially at the moment, so a stream
     # can only be read once.
     assert not self._callback
     self._trace_file_handle = trace_data_module.TraceFileHandle()
     self._trace_file_handle.Open()
     self._callback = callback
     self._ReadChunkFromStream()
     # The below is not a typo -- queue one extra read ahead to avoid latency.
     self._ReadChunkFromStream()
Beispiel #3
0
 def testB64EncodedCompressedData(self):
   is_compressed = True
   handle = trace_data.TraceFileHandle(is_compressed)
   handle.Open()
   original_data = {"msg": "The answer is 42"}
   # gzip.compress() does not work in python 2. So hardcode the encoded data
   # here.
   b64_compressed_data = "H4sIAIDMblwAA6tWyi1OV7JSUArJSFVIzCs" \
       "uTy1SyCxWMDFSquUCAA4QMtscAAAA"
   handle.AppendTraceData(b64_compressed_data, b64=True)
   handle.Close()
   out_data = handle.AsTraceData()
   self.assertEqual(original_data, out_data)