unit uBlobStream;

interface

uses Rubies;

var
  cBlobStream: Tvalue;

procedure Init_BlobStream;

implementation

uses DB, DBTables, uDefUtils, Pythia, uDatabase, uRDBExt;

function BlobStream_new(argc: Integer; argv: Pointer; This: Tvalue): Tvalue; cdecl;
var
  p: Pvalue;
  field: TBlobField;
  mode: TBlobStreamMode;
  real: TBlobStream;
begin
  if argc < 1 then ap_raise(ap_eArgError, sToo_few_args);
  p := argv;

  ap_data_get_object(p^, TBlobField, field); inc(p);

  if argc > 1 then
    mode := TBlobStreamMode(FIX2INT(p^))
  else
    mode := bmRead;

  real := TBlobStream.Create(field, mode);
  result := ObjAlloc(This, real);

  ap_obj_call_init(result, argc, argv);
end;

function BlobStream_alloc(This: Tvalue; real: TBlobStream): Tvalue;
begin
  result := TmpAlloc(This, real);
end;

procedure Init_BlobStream;
begin
  cBlobStream := rb_define_class_under(ap_mRDB, 'BlobStream', ap_cStream);
  DefineSingletonMethod(cBlobStream, 'new', BlobStream_new);
end;

end.
