Sha256: fcd2cc0479e2b8684daefe46ee954b0528af13175990489a2349a23cd7c910a9

Contents?: true

Size: 1.52 KB

Versions: 35

Compression:

Stored size: 1.52 KB

Contents

// :mode=c++:
/*
encode.h - c++ wrapper for a base64 encoding algorithm

This is part of the libb64 project, and has been placed in the public domain.
For details, see http://sourceforge.net/projects/libb64
*/
#ifndef BASE64_ENCODE_H
#define BASE64_ENCODE_H

#include <iostream>

namespace base64
{
	extern "C"
	{
		#include "cencode.h"
	}

	struct encoder
	{
		base64_encodestate _state;
		int _buffersize;

		encoder(int buffersize_in = BUFFERSIZE)
		: _buffersize(buffersize_in)
		{}

		int encode(char value_in)
		{
			return base64_encode_value(value_in);
		}

		int encode(const char* code_in, const int length_in, char* plaintext_out)
		{
			return base64_encode_block(code_in, length_in, plaintext_out, &_state);
		}

		int encode_end(char* plaintext_out)
		{
			return base64_encode_blockend(plaintext_out, &_state);
		}

		void encode(std::istream& istream_in, std::ostream& ostream_in)
		{
			base64_init_encodestate(&_state);
			//
			const int N = _buffersize;
			char* plaintext = new char[N];
			char* code = new char[2*N];
			int plainlength;
			int codelength;

			do
			{
				istream_in.read(plaintext, N);
				plainlength = static_cast<int>(istream_in.gcount());
				//
				codelength = encode(plaintext, plainlength, code);
				ostream_in.write(code, codelength);
			}
			while (istream_in.good() && plainlength > 0);

			codelength = encode_end(code);
			ostream_in.write(code, codelength);
			//
			base64_init_encodestate(&_state);

			delete [] code;
			delete [] plaintext;
		}
	};

} // namespace base64

#endif // BASE64_ENCODE_H

Version data entries

35 entries across 35 versions & 4 rubygems

Version Path
sassc-1.11.4 ext/libsass/src/b64/encode.h
sassc-1.11.3 ext/libsass/src/b64/encode.h
lanes-0.8.0 node_modules/node-sass/src/libsass/src/b64/encode.h
sassc-1.11.2 ext/libsass/src/b64/encode.h
sassc-1.11.1 ext/libsass/src/b64/encode.h
sassc-1.11.0 ext/libsass/src/b64/encode.h
sassc-1.10.1 ext/libsass/src/b64/encode.h
sassc-1.10.0 ext/libsass/src/b64/encode.h
blackboard-3.1.9 lib/site_template/node_modules/node-sass/src/libsass/src/b64/encode.h
sassc-1.9.0 ext/libsass/src/b64/encode.h
sassc-1.8.5 ext/libsass/src/b64/encode.h
sassc-1.8.4 ext/libsass/src/b64/encode.h
sassc-1.8.3 ext/libsass/src/b64/encode.h
sassc-1.8.2 ext/libsass/src/b64/encode.h
sassc-1.8.1 ext/libsass/src/b64/encode.h
sassc-1.8.0 ext/libsass/src/b64/encode.h
sassc-1.8.0.pre2 ext/libsass/src/b64/encode.h
sassc-1.8.0.pre1 ext/libsass/src/b64/encode.h
gulp_assets-1.0.0.pre.5 template/node_modules/gulp-sass/node_modules/node-sass/src/libsass/b64/encode.h
gulp_assets-1.0.0.pre.4 template/node_modules/gulp-sass/node_modules/node-sass/src/libsass/b64/encode.h