Class: Net::SMB::File
- Inherits:
-
Object
- Object
- Net::SMB::File
- Defined in:
- ext/net_smb/smbfile.c
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #eof? ⇒ Boolean (also: #eof)
- #initialize(*args) ⇒ Object constructor
- #pos ⇒ Object (also: #tell)
- #pos=(offset) ⇒ Object
- #read(*args) ⇒ Object
- #read_buffer_size ⇒ Object
- #rewind ⇒ Object
- #seek(*args) ⇒ Object
- #smb ⇒ Object
- #stat ⇒ Object
- #url ⇒ Object
- #xattr(name_obj) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'ext/net_smb/smbfile.c', line 156
static VALUE rb_smbfile_initialize(int argc, VALUE *argv, VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
VALUE smb_obj, url_obj, mode_obj;
rb_scan_args(argc, argv, "21", &smb_obj, &url_obj, &mode_obj);
RB_SMB_DATA_FROM_OBJ(smb_obj, smb_data);
if (NIL_P(mode_obj)) {
data->fmode = FMODE_READABLE;
// FIXME data->fmode = FMODE_READABLE | DEFAULT_TEXTMODE;
data->oflags = O_RDONLY;
}
else if (FIXNUM_P(mode_obj)) {
rb_raise(rb_eArgError, "FIXME");
data->fmode = 0;
data->oflags = NUM2INT(mode_obj);
}
else {
const char *mode_str = StringValueCStr(mode_obj);
data->fmode = rb_io_modestr_fmode(mode_str);
data->oflags = rb_io_modestr_oflags(mode_str);
}
data->smb_obj = smb_obj;
data->smb_data = smb_data;
data->smbcctx = smb_data->smbcctx;
data->url = ruby_strdup(RSTRING_PTR(url_obj));
data->buffer = ruby_xmalloc(RB_SMBFILE_BUFFER_SIZE);
data->buffer_size = RB_SMBFILE_BUFFER_SIZE;
rb_smbfile_open_by_data(data);
if (rb_block_given_p()) {
return rb_ensure(rb_yield, self, rb_smbfile_close, self);
}
return self;
}
|
Instance Method Details
#close ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 |
# File 'ext/net_smb/smbfile.c', line 216
static VALUE rb_smbfile_close(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMBFILE_DATA_CLOSED(data);
RB_SMB_DEBUG("data=%p smbcctx=%p smbcfile=%p\n", data, data->smbcctx, data->smbcfile);
rb_smbfile_close_and_deref_by_data(data);
return self;
}
|
#closed? ⇒ Boolean
231 232 233 234 235 236 |
# File 'ext/net_smb/smbfile.c', line 231
static VALUE rb_smbfile_closed_p(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
return rb_smbfile_closed_p_by_data(data);
}
|
#eof? ⇒ Boolean Also known as: eof
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'ext/net_smb/smbfile.c', line 306
static VALUE rb_smbfile_eof_p(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMBFILE_DATA_CLOSED(data);
if (data->buffer_used_size - data->buffer_pos > 0) {
/* Remained data exist in buffer */
return Qfalse;
}
/* Try to read from file to buffer */
rb_smbfile_read_by_data(data);
if (data->buffer_used_size - data->buffer_pos > 0) {
/* Remained data exist in buffer */
return Qfalse;
}
return Qtrue;
}
|
#pos ⇒ Object Also known as: tell
250 251 252 253 254 255 256 |
# File 'ext/net_smb/smbfile.c', line 250
static VALUE rb_smbfile_pos(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMBFILE_DATA_CLOSED(data);
return SIZET2NUM(data->pos);
}
|
#pos=(offset) ⇒ Object
294 295 296 297 |
# File 'ext/net_smb/smbfile.c', line 294
static VALUE rb_smbfile_pos_set(VALUE self, VALUE offset)
{
return rb_smbfile_seek(1, &offset, self);
}
|
#read(*args) ⇒ Object
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'ext/net_smb/smbfile.c', line 334
static VALUE rb_smbfile_read(int argc, VALUE *argv, VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMBFILE_DATA_CLOSED(data);
ssize_t req_read_size;
VALUE str = rb_str_new2("");
rb_smbfile_readable_p_by_data(data);
if (argc == 0) {
req_read_size = -1;
}
else {
req_read_size = NUM2SSIZET(argv[0]);
if (req_read_size == 0) {
return str; /* Return empty string */
}
if (req_read_size < 0) {
rb_raise(rb_eArgError, "Negative length given: %zd", req_read_size);
}
}
while (req_read_size) {
ssize_t buffer_read_size = data->buffer_used_size - data->buffer_pos;
if (buffer_read_size == 0) {
/* No remained data in buffer */
rb_smbfile_read_by_data(data);
if (data->eof) {
/* No remained data in file */
return (req_read_size > 0 && RSTRING_LEN(str) == 0) ? Qnil : str;
}
buffer_read_size = data->buffer_used_size - data->buffer_pos;
}
if (req_read_size > 0 && buffer_read_size > req_read_size) {
buffer_read_size = req_read_size;
}
rb_str_cat(str, data->buffer + data->buffer_pos, buffer_read_size);
data->pos += buffer_read_size;
data->buffer_pos += buffer_read_size;
if (req_read_size > 0) {
req_read_size -= buffer_read_size;
}
}
return str;
}
|
#read_buffer_size ⇒ Object
211 212 213 214 |
# File 'ext/net_smb/smbfile.c', line 211
static VALUE rb_smbfile_read_buffer_size(VALUE self)
{
return INT2NUM(RB_SMBFILE_BUFFER_SIZE);
}
|
#rewind ⇒ Object
299 300 301 302 303 304 |
# File 'ext/net_smb/smbfile.c', line 299
static VALUE rb_smbfile_rewind(VALUE self)
{
VALUE argv = OFFT2NUM(0);
return rb_smbfile_seek(1, &argv, self);
}
|
#seek(*args) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'ext/net_smb/smbfile.c', line 258
static VALUE rb_smbfile_seek(int argc, VALUE *argv, VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMBFILE_DATA_CLOSED(data);
VALUE whence_num;
rb_scan_args(argc, argv, "11", NULL, &whence_num);
off_t offset = NUM2OFFT(argv[0]);
int whence = NIL_P(whence_num) ? SEEK_SET : NUM2INT(whence_num);
switch (whence) {
case SEEK_SET:
data->pos = offset;
break;
case SEEK_CUR:
if (offset < 0 && offset < -data->pos) {
errno = EINVAL;
rb_sys_fail(data->url);
}
data->pos += offset;
break;
case SEEK_END:
/* FIXME */
rb_raise(rb_eNotImpError, "SEEK_END");
break;
default:
errno = EINVAL;
rb_sys_fail(data->url);
break;
}
rb_smbfile_seek_by_data(data);
return self;
}
|
#smb ⇒ Object
197 198 199 200 201 202 |
# File 'ext/net_smb/smbfile.c', line 197
static VALUE rb_smbfile_smb(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
return data->smb_obj;
}
|
#stat ⇒ Object
238 239 240 241 |
# File 'ext/net_smb/smbfile.c', line 238
static VALUE rb_smbfile_stat(VALUE self)
{
return rb_class_new_instance(1, &self, rb_cSMBStat);
}
|
#url ⇒ Object
204 205 206 207 208 209 |
# File 'ext/net_smb/smbfile.c', line 204
static VALUE rb_smbfile_url(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
return rb_str_new2(data->url);
}
|
#xattr(name_obj) ⇒ Object
243 244 245 246 247 248 |
# File 'ext/net_smb/smbfile.c', line 243
static VALUE rb_smbfile_xattr_get(VALUE self, VALUE name_obj)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
return rb_smb_xattr_get(data->smb_obj, rb_str_new2(data->url), name_obj);
}
|