aboutsummaryrefslogtreecommitdiff
path: root/src/tests/base64.cpp
blob: 413ff92557e1327ec4237f8b1fbaac6504993b86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/file.h"
#include "bu/membuf.h"
#include "bu/base64.h"

int main( int argc, char *argv[] )
{
	argc--,argv++;

	if( argc < 3 )
		return 0;

	if( argv[0][0] == 'e' )
	{
		argv++;
		Bu::File fIn( argv[0], Bu::File::Read );
		Bu::File fOut( argv[1], Bu::File::WriteNew );
		Bu::Base64 bOut( fOut );

		char buf[900];
		for(;;)
		{
			int iRead = fIn.read( buf, 900 );
			bOut.write( buf, iRead );
			if( iRead < 900 )
				break;
		}
	}
	else if( argv[0][0] == 'd' )
	{
		argv++;
		Bu::File fIn( argv[0], Bu::File::Read );
		Bu::File fOut( argv[1], Bu::File::WriteNew );
		Bu::Base64 bIn( fIn );

		char buf[1024];
		for(;;)
		{
			int iRead = bIn.read( buf, 1024 );
			printf("Read %d bytes.\n", iRead );
			fOut.write( buf, iRead );
			if( iRead == 0 )
				break;
		}
	}
	else if( argv[0][0] == 'D' )
	{
		argv++;
		Bu::MemBuf mIn;
		{
			Bu::File fIn( argv[0], Bu::File::Read );
			char buf[1024];
			for(;;)
			{
				int iRead = fIn.read( buf, 1024 );
				mIn.write( buf, iRead );
				if( iRead < 1024 )
					break;
			}
			mIn.setPos( 0 );
		}
		Bu::File fOut( argv[1], Bu::File::WriteNew );
		Bu::Base64 bIn( mIn );

		char buf[1024];
		for(;;)
		{
			int iRead = bIn.read( buf, 1024 );
			printf("Read %d bytes.\n", iRead );
			fOut.write( buf, iRead );
			if( iRead == 0 )
				break;
		}
	}

	return 0;
}