Lasso Soft Inc. > Home

[bytes_format]

Linkbytes_format
AuthorJason Huck
CategoryFile
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted25 Oct 2005
Updated16 Jan 2006
More by this author...

Description

Tags the supplied integer as a number of bytes and returns it as a string converted to kb, mb, or gb, depending on the size.

Sample Usage

var('myFile') = file(
    'somefile.txt', 
    file_openread,
    file_modechar
);

bytes_format($myFile->getsize);

-> 2.23 mb

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag(
	'format',
	-namespace='bytes_',
	-priority='replace',
	-description='Converts bytes to kilobytes, megabytes, or gigabytes for display.'
);
	fail_if(
		!params->first || !params->first->isa('integer'),
		-1,
		'[bytes_format] requires an integer as input.'
	);
	
	local(
		'in' = decimal(params->first),
		'd' = decimal(1024),
		'c' = 1,
		'u' = array(
			'bytes',
			'kb',
			'mb',
			'gb'
		)
	);
	
	#in->setformat( -precision=2);
	
	while(true);
		if(#in < #d);
			local('out') = (#c == 1 ? integer(#in) | #in);
			return(#out + ' ' + #u->get(#c));
		else;
			#in /= #d;
			#c += 1;
		/if;
	/while;
/define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft