Commit 790db7db authored by Zhukov, Alexander P's avatar Zhukov, Alexander P
Browse files

[] now supports negative indices

parent a89dfac5
This diff is collapsed.
<?xml version='1.0' encoding='UTF-8'?>
<Project Type="Project" LVVersion="18008000">
<Property Name="CCSymbols" Type="Str"></Property>
<Property Name="NI.LV.All.SourceOnly" Type="Bool">true</Property>
<Property Name="NI.Project.Description" Type="Str"></Property>
<Property Name="SMProvider.SMVersion" Type="Int">201310</Property>
<Item Name="My Computer" Type="My Computer">
<Property Name="IOScan.Faults" Type="Str"></Property>
<Property Name="IOScan.NetVarPeriod" Type="UInt">100</Property>
<Property Name="IOScan.NetWatchdogEnabled" Type="Bool">false</Property>
<Property Name="IOScan.Period" Type="UInt">10000</Property>
<Property Name="IOScan.PowerupMode" Type="UInt">0</Property>
<Property Name="IOScan.Priority" Type="UInt">9</Property>
<Property Name="IOScan.ReportModeConflict" Type="Bool">true</Property>
<Property Name="IOScan.StartEngineOnDeploy" Type="Bool">false</Property>
<Property Name="NI.SortType" Type="Int">3</Property>
<Property Name="server.app.propertiesEnabled" Type="Bool">true</Property>
<Property Name="server.control.propertiesEnabled" Type="Bool">true</Property>
<Property Name="server.tcp.enabled" Type="Bool">false</Property>
<Property Name="server.tcp.port" Type="Int">0</Property>
<Property Name="server.tcp.serviceName" Type="Str">My Computer/VI Server</Property>
<Property Name="server.tcp.serviceName.default" Type="Str">My Computer/VI Server</Property>
<Property Name="server.vi.callsEnabled" Type="Bool">true</Property>
<Property Name="server.vi.propertiesEnabled" Type="Bool">true</Property>
<Property Name="specify.custom.address" Type="Bool">false</Property>
<Item Name="TestStorage.vi" Type="VI" URL="../TestStorage.vi"/>
<Item Name="BinStorage.lvclass" Type="LVClass" URL="../BinStorage.lvclass"/>
<Item Name="Dependencies" Type="Dependencies"/>
<Item Name="Build Specifications" Type="Build"/>
</Item>
</Project>
<?xml version='1.0' encoding='UTF-8'?>
<Project Type="Project" LVVersion="18008000">
<Property Name="CCSymbols" Type="Str"></Property>
<Property Name="NI.LV.All.SourceOnly" Type="Bool">true</Property>
<Property Name="NI.Project.Description" Type="Str"></Property>
<Property Name="SMProvider.SMVersion" Type="Int">201310</Property>
<Item Name="My Computer" Type="My Computer">
<Property Name="IOScan.Faults" Type="Str"></Property>
<Property Name="IOScan.NetVarPeriod" Type="UInt">100</Property>
<Property Name="IOScan.NetWatchdogEnabled" Type="Bool">false</Property>
<Property Name="IOScan.Period" Type="UInt">10000</Property>
<Property Name="IOScan.PowerupMode" Type="UInt">0</Property>
<Property Name="IOScan.Priority" Type="UInt">9</Property>
<Property Name="IOScan.ReportModeConflict" Type="Bool">true</Property>
<Property Name="IOScan.StartEngineOnDeploy" Type="Bool">false</Property>
<Property Name="NI.SortType" Type="Int">3</Property>
<Property Name="server.app.propertiesEnabled" Type="Bool">true</Property>
<Property Name="server.control.propertiesEnabled" Type="Bool">true</Property>
<Property Name="server.tcp.enabled" Type="Bool">false</Property>
<Property Name="server.tcp.port" Type="Int">0</Property>
<Property Name="server.tcp.serviceName" Type="Str">My Computer/VI Server</Property>
<Property Name="server.tcp.serviceName.default" Type="Str">My Computer/VI Server</Property>
<Property Name="server.vi.callsEnabled" Type="Bool">true</Property>
<Property Name="server.vi.propertiesEnabled" Type="Bool">true</Property>
<Property Name="specify.custom.address" Type="Bool">false</Property>
<Item Name="TestStorage.vi" Type="VI" URL="../TestStorage.vi"/>
<Item Name="BinStorage.lvclass" Type="LVClass" URL="../BinStorage.lvclass"/>
<Item Name="Dependencies" Type="Dependencies"/>
<Item Name="Build Specifications" Type="Build"/>
</Item>
</Project>
......@@ -7,12 +7,14 @@ Created on Mon Jan 27 16:14:52 2020
"""
from read_storage import *
from read_storage import BinaryStorage
file = open('/data/BinStorage/test.bin','rb')
bytes = file.read(12)
print(bytes.decode())
# file = open('/data/BinStorage/test.bin','rb')
# bytes = file.read(12)
# print(bytes.decode())
read_epilog(file)
file = BinaryStorage('/data/BinStorage/test.bin')
print(file[0])
file.close()
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 27 16:11:06 2020
@author: az9
"""
from read_storage import BinaryStorage
# file = open('/data/BinStorage/test.bin','rb')
# bytes = file.read(12)
# print(bytes.decode())
file = BinaryStorage('/data/BinStorage/test.bin')
while True:
record = file.read_record()
if 'EOF' in record:
break
print(record)
file.close()
\ No newline at end of file
......@@ -11,11 +11,16 @@ import os
class BinaryStorage:
HEADER_SZ=12
def __init__(self, path):
self.file = open('/data/BinStorage/test.bin','rb')
bytes = self.file.read(12)
print(bytes.decode())
bytes = self.file.read(BinaryStorage.HEADER_SZ)
# print(bytes.decode())
self.rec_table = BinaryStorage.read_epilog(self.file)
self.file.seek(BinaryStorage.HEADER_SZ)
def close(self):
......@@ -24,6 +29,14 @@ class BinaryStorage:
def read(self):
return BinaryStorage.read_record(self.file)
def __getitem__(self, key):
offset = self.rec_table[key]
self.file.seek(offset)
return BinaryStorage.read_record(self.file)
def __len__(self):
return len(self.rec_table)
......@@ -164,21 +177,22 @@ class BinaryStorage:
if not result:
break
return record
def read_epilog(file):
OFST_SIZE=8
file.seek(-4,os.SEEK_END)
raw = array('I',file.read(4))
raw.byteswap()
num_records = raw[0]
num_records = raw[0]
print(num_records)
file.seek(-4-OFST_SIZE*num_records,os.SEEK_END)
raw = array('L',file.read(OFST_SIZE*num_records))
raw.byteswap()
print(raw.itemsize)
print(raw)
file.seek(-4-OFST_SIZE*num_records,os.SEEK_END)
# the last record is EOF, and the very last offset has nothing
raw = array('L',file.read(OFST_SIZE*(num_records-2)))
raw.byteswap()
# print(raw.itemsize)
# print(raw)
return raw
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment