2019-02-10 23:11:01 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* ft_base64_encode.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2019/02/10 20:52:07 by gtertysh #+# #+# */
|
|
|
|
/* Updated: 2019/02/10 20:52:59 by gtertysh ### ########.fr */
|
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include <unistd.h>
|
2019-02-02 19:13:36 +02:00
|
|
|
#include "ft_base64.h"
|
2019-02-10 23:11:01 +02:00
|
|
|
#include "libft.h"
|
2019-02-02 19:13:36 +02:00
|
|
|
|
2019-02-07 23:22:40 +02:00
|
|
|
void ft_base64_encode(t_base64_ctx *ctx)
|
2019-02-02 19:13:36 +02:00
|
|
|
{
|
2019-02-10 23:11:01 +02:00
|
|
|
t_byte1 buff[FT_BASE64_READ_SIZE + FT_BASE64_TRANS_SIZE];
|
|
|
|
t_byte8 readed;
|
|
|
|
t_byte8 reminder;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = ctx->input_fd;
|
|
|
|
reminder = 0;
|
|
|
|
while ((readed = read(fd, buff + reminder, FT_BASE64_READ_SIZE)) > 0)
|
|
|
|
{
|
|
|
|
if (readed >= FT_BASE64_TRANS_SIZE)
|
|
|
|
{
|
|
|
|
reminder = ft_base64_encode_step(ctx, readed, buff);
|
|
|
|
ft_memmove(buff, buff + readed - reminder, reminder);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reminder += readed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ft_base64_encode_finish(ctx, reminder, buff);
|
|
|
|
}
|