# Module to check if file contains a character

**URL:** <https://www.ruby-forum.com/t/module-to-check-if-file-contains-a-character/227476>\
**Category:** NGINX\
**Created:** [March 16, 2013, 4:15pm UTC](https://www.ruby-forum.com/t/module-to-check-if-file-contains-a-character/227476 "2013-03-16T16:15:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexanderk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alexanderk](https://www.ruby-forum.com/u/alexanderk)\
**Post date:** [March 16, 2013, 4:15pm UTC](https://www.ruby-forum.com/t/module-to-check-if-file-contains-a-character/227476/1 "2013-03-16T16:15:39Z")

</div>

Hello,

Without reading the whole file, what is the best approach to only check  
if the beginning of the file contains a specific character?

Would something like this be the right approach?

b = ngx\_pcalloc(r-\>pool, sizeof(ngx\_buf\_t));  
b-\>file = ngx\_pcalloc(r-\>pool, sizeof(ngx\_file\_t));

then set file\_pos, file\_last etc.

and later do ngx\_cpymem(s, b-\>pos, size) to copy it in a u\_char and then  
do a if s[0] == ?

Thanks,

Alex
