Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
javiermarinros committed Jun 21, 2013
0 parents commit af22ba9
Show file tree
Hide file tree
Showing 6 changed files with 743 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
215 changes: 215 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

#############
## Windows detritus
#############

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg
159 changes: 159 additions & 0 deletions Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php

/**
* Representa la interfaz común de todos los compresores de archivos
*/
abstract class Archive_Base {

protected $_data = array();

/**
* Nivel de compresión de 0 a 100, donde 100 es compresión máxima
* @var int
*/
public $level = 75;

/**
* Mensajes de adventencia o error obtenidos durante la creación del fichero
* @var string[]
*/
public $log;

/**
* Añade un fichero(s) al archivo dada su ruta
* @param string|string[] $path
* @param string $local_name Nombre que tendrá el archivo en el fichero creado
*/
public function add_file($path, $local_name = NULL) {
if (is_array($path)) {
foreach ($path as $p) {
$this->_data[] = array(
'path' => $path,
'name' => $path
);
}
} else {
$this->_data[] = array(
'path' => $path,
'name' => isset($local_name) ? $local_name : $path
);
}
}

/**
* Añade un fichero al archivo dado su contenido
*/
public function add_data($local_name, $content) {

$this->_data[] = array(
'content' => $content,
'name' => $local_name
);
}

/**
* Añade un directorio al archivo
*/
public function add_folder($local_name) {
$this->_data[] = array(
'is_dir' => TRUE,
'content' => '',
'name' => $local_name
);
}

/**
* Limpia el archivo actual, comenzando uno nuevo
*/
public function clear() {
$this->_data = array();
$this->log = array();
}

/**
* Prepara la lista y jerarquía de los archivos a comprimir
* @return Archive_File[]
*/
protected function _get_files() {
$files = array();

//Incluir archivos e información sobre ellos
foreach ($this->_data as $info) {
$file = new Archive_File();
$file->path = $info['name'];

if (isset($info['content'])) {
$file->content = $info['content'];
$file->is_directory = isset($info['is_dir']) && $info['is_dir'];
} else {
$file->real_path = realpath($info['path']);

if (!$file->real_path) {
$this->log[] = "File {$info['path']} not found";
continue;
}

$file->is_directory = is_dir($file->real_path);
}

$files[] = $file;
}

//Ordenar archivos (según carpeta, tipo, etc.)
if (!function_exists('_archive_sort_files')):

function _archive_sort_files(Archive_File $a, Archive_File $b) {
//Order por carpetas, extensiones y nombre
$a_folder = dirname($a->path);
$b_folder = dirname($b->path);
if ($a_folder != $b_folder) {
return strcmp($a_folder, $b_folder);
} else {
//Archivos juntos del mismo tipo se comprimen mejor (compresión sólida)
$a_ext = pathinfo($a->path, PATHINFO_EXTENSION);
$b_ext = pathinfo($b->path, PATHINFO_EXTENSION);
if ($a_ext != $b_ext)
return strcmp($a_ext, $b_ext);
else
return strcmp($a->path, $b->path);
}
}

endif;

usort($files, '_archive_sort_files');

return $files;
}

/**
* Crea el archivo comprimido en la ruta indicada
*/
public abstract function create($path);
}

/**
* @access private
*/
class Archive_File {

public $path;
public $real_path = FALSE;
public $content = FALSE;
public $is_directory;

public function stats() {
if ($this->real_path) {
return stat($this->real_path);
} else {
return array(
'mode' => 0777, //Modo
'uid' => 0, //Usuario
'gid' => 0, //Grupo
'size' => strlen($this->content), //Tamaño
'mtime' => time(), //Fecha de modificación
);
}
}

}
Loading

0 comments on commit af22ba9

Please sign in to comment.