Hello,
I have got some strange effects.
Could you please confirm :
PgSqlLargeObject.Read(buf, offset, size) (and same for Write).
The doc is ambiguous : I finally found that 'offset', is relative to the largeobject from the beginning, not an offset into the buffer.
All examples provided load the lo in one shot. But in my application, i have to update a progress bar.
If you look in my code below, i define a segment size (4096*10), and i read (or write) the lo segment by segment, plus the last 'incomplete' segment.
It looks like the lo.seek is not relevant.
Can you test on your side a test for a file, let says 100Ko, written segment by segment, idem for the read. I guess you will be surprised.
One remark : I do not find the lo in pg_catalog.pg_largeobject. Is this normal ?
One question : when will it be possible to download the mainstream updates with the memcrypt ??
Seb
public static byte[] GetBytes( Int32 lob) {
byte[] cry = new byte[0];
DBC cc = new DBC();
int fsz;
Int32 rd;
PgSqlLargeObject lobj;
Int32 sz;
Int32 numseg;
Int32 lastsize;
lock ( Lo_lock ) {
try {
cc.BeginTransaction();
lobj = new PgSqlLargeObject(cc, lob, false);
lobj.Open();
if ( !lobj.CanRead ) {
lobj.Close ( );
cc.Commit ( );
lutils.MyTrace ( "GetBytes lob=" + lob + ", CANNOT READ !!!" );
return new byte[ 0 ];
}
sz=(int)lobj.Length;
numseg = sz / SEG_SIZE2;
lastsize = Convert.ToInt32 ( sz % SEG_SIZE2 );
lutils.MyTrace ( "GetBytes POS:"+lobj.Position+" LOB:"+lob+" sz=" + sz + " numseg=" + numseg + " lastsize=" + lastsize + " resultant=" + ( ( numseg * SEG_SIZE2 ) + lastsize ) );
fsz = (int)lobj.Length;
cry = new Byte[fsz];
cry.Initialize ( );
byte[] loc = new byte[ SEG_SIZE2 ];
for ( int i=0; i 0 ) {
int st = numseg * SEG_SIZE2;
lutils.MyTrace ( "GetBytes AVANT seg:LAST Pos:" + lobj.Position + " " + cry[ st ].ToString ( "X2" )
+ ( lastsize > 1 ? " " + cry[ st + 1 ].ToString ( "X2" ) : "" )
+ " " + ( lastsize > 2 ? " " + cry[ st + 2 ].ToString ( "X2" ) : "" )
+ " " + ( lastsize > 3 ? " " + cry[ st + 3 ].ToString ( "X2" ) : "" ) );
byte[] loc2 = new byte[ lastsize ];
loc2.Initialize ( );
lobj.Read ( loc2, st, lastsize );
Array.Copy ( loc2, 0, cry, st, lastsize );
lutils.MyTrace ( "GetBytes APRES seg:LAST Pos:" + lobj.Position + " " + cry[ st ].ToString ( "X2" )
+ ( lastsize > 1 ? " " + cry[ st + 1 ].ToString ( "X2" ) : "" )
+ " " + ( lastsize > 2 ? " " + cry[ st + 2 ].ToString ( "X2" ) : "" )
+ " " + ( lastsize > 3 ? " " + cry[ st + 3 ].ToString ( "X2" ) : "" ) );
}
lutils.MyTrace ( "GetBytes lob=" + lob + ", length=" + lobj.Length + ", (int)len=" + fsz );
lobj.Close();
cc.Commit();
}
catch(Exception ee) {
String s = ee.ToString();
s += " ";
return new byte[0];
//throw new Exception("GetBytes");
}
}
cc.Close();
return cry;
}
LargeObject Read and Write question
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
PgSqlLargeObject.Read(buf, offset, size) - offset: The zero-based byte offset in buffer at which to begin storing the data read from the large object.baba wrote:The doc is ambiguous : I finally found that 'offset', is relative to the largeobject from the beginning, not an offset into the buffer.
If you read data segment by segment you do not need to use lo.seek(...). Reading the next segment will begin from the position where reading the privious segment has ended.baba wrote:If you look in my code below, i define a segment size (4096*10), and i read (or write) the lo segment by segment, plus the last 'incomplete' segment.
It looks like the lo.seek is not relevant.
We have tested reading data segment by segment and all works correctly. I've changed the part of your code where you use the "for" loop:baba wrote:Can you test on your side a test for a file, let says 100Ko, written segment by segment, idem for the read. I guess you will be surprised.
Code: Select all
for ( int i=0; i 0 ) {
int st = numseg * SEG_SIZE2;
byte[] loc2 = new byte[ lastsize ];
lobj.Read ( loc2, 0, lastsize );
Array.Copy ( loc2, 0, cry, st, lastsize );
}
Try to search your lo in pg_catalog.pg_largeobject_metadatababa wrote:One remark : I do not find the lo in pg_catalog.pg_largeobject. Is this normal ?
We are planning to do it in a month or two.baba wrote:One question : when will it be possible to download the mainstream updates with the memcrypt ??