# Streaming from file

**URL:** <https://www.ruby-forum.com/t/streaming-from-file/224488>\
**Category:** GNU Radio\
**Created:** [November 13, 2012, 10:33pm UTC](https://www.ruby-forum.com/t/streaming-from-file/224488 "2012-11-13T22:33:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 13, 2012, 10:33pm UTC](https://www.ruby-forum.com/t/streaming-from-file/224488/1 "2012-11-13T22:33:17Z")

</div>

Hi all,

I am working on a custom block that tags a stream based on a binary file  
stretched into unpacked form:

(1) (2)  
(3)  
gr\_file\_source(repeat=false) --\> gr\_packed\_to\_unpacked(1, gr.MSB\_FIRST)  
–\> my\_block

I want to come up with a good way to detect in my\_block whether the  
stream input from (2) is finished. I guess gr\_file\_source will return  
WORK\_DONE first, but I don’t know if/how that ripples down to my\_block.  
Basically I want to be able to tag the last incoming sample with an  
end-of-burst tag, but I don’t know how to do this without having advance  
knowledge about the size of the source file.

Thanks,  
Sean

---

<div class="post-metadata">

**Author:** ![NowlanS\_Sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f05b48/32.png) [@NowlanS\_Sean](https://www.ruby-forum.com/u/NowlanS_Sean)\
**Post date:** [November 14, 2012, 4:43am UTC](https://www.ruby-forum.com/t/streaming-from-file/224488/2 "2012-11-14T04:43:41Z")

</div>

On Tue, Nov 13, 2012 at 4:32 PM, Nowlan, Sean  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> (3)  
> but I dont know how to do this without having advance knowledge about the  
> size of the source file.
> 
> Thanks,
> 
> Sean

Sean,

Yeah, you won’t be able to tell if you’re at the end of the file or if  
the scheduler just passed you 0 items to process. There’s no  
indication of that.

Probably the easiest thing for you to do is quickly edit the file  
source block to generate the tag when it reaches EOF. That should be  
pretty straight-forward.

Tom

---

<div class="post-metadata">

**Author:** ![NowlanS\_Sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f05b48/32.png) [@NowlanS\_Sean](https://www.ruby-forum.com/u/NowlanS_Sean)\
**Post date:** [November 21, 2012, 5:33pm UTC](https://www.ruby-forum.com/t/streaming-from-file/224488/3 "2012-11-21T17:33:52Z")

</div>

On Wed, Nov 14, 2012 at 9:35 AM, Nowlan, Sean  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Good point. That’s probably what I’ll do.
> 
> Is there any way to check whether upstream blocks are done? From examining  
> gr\_block\_executor, it knows how to do this, so would it make sense to have it  
> alert downstream blocks?

I was thinking about this and then forgot to reply. The answer is, I’m  
pretty sure, no (at least, not without added overhead). You’d break  
some of the independence of blocks if you tried to organize something  
like. What the scheduler does is look to see if anyone has returned  
-1, which will happen if a source is finished (like after reading a  
file) or from someone like a gr\_head block. This propagates down to  
the scheduler who uses this info to start cleaning up, which means  
pushing through any more existing items through the blocks and to the  
sinks. You couldn’t really put something into another block because  
there still might be items coming to it from upstream even if the  
source(s) is(are) finished.

Tom

---

<div class="post-metadata">

**Author:** ![NowlanS\_Sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f05b48/32.png) [@NowlanS\_Sean](https://www.ruby-forum.com/u/NowlanS_Sean)\
**Post date:** [November 14, 2012, 4:16pm UTC](https://www.ruby-forum.com/t/streaming-from-file/224488/4 "2012-11-14T16:16:51Z")

</div>

Good point. That’s probably what I’ll do.

Is there any way to check whether upstream blocks are done? From  
examining gr\_block\_executor, it knows how to do this, so would it make  
sense to have it alert downstream blocks?
